I want to insert some values into my table based on a users input. I get these values from some textboxes. When i put a breakpoint before my SQL logic, and go through every line with F10, everything works just fine. I open the SQLConnection
, create a SQLCommand
, execute it, and close the connection again. I refresh the table and have all the values in there. But when I delete or disable the breakpoint, and the programm goes over these lines of code by itself, it doesn't work, meaning no values are being added to the table, no matter how often i refresh.
Here is the code I'm referring to:
try
{
SqlConnection con = new SqlConnection("Server=...;Database=...;Integrated Security=true;");
con.Open();
SqlCommand com = new SqlCommand("INSERT INTO TestTable (Type,Serialnumber) VALUES('" + TypeText + "','" + SerText + "')", con);
//Debug.WriteLine(com.CommandText);
com.BeginExecuteNonQuery();
con.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}