When I try to use the application to add new rows to my database everything goes OK, but when I close the program the database does not contain the newly inserted row.
Below is my code:
string n;
n = txtNaslov.Text;
SqlConnection con = new SqlConnection("my connection string...");
try
{
SqlCommand cmd = new SqlCommand("insert into Table1 values('" + n + "', con);
//i ve added the other
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
catch (SqlException ex)
{
}
finally
{
}
What am I doing wrong?
Try to invert some lines…
First Open your cmd and then set your SQL Statement,
this may be wiping out your sql.
Don’t discard David’s comment, fill catch statement, it can show you what are you donig wrong