using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand("INSERT INTO Alarm (artistname, tijd) VALUES (@artistname, @tijd)", connection);
cmd.CommandType = CommandType.Text;
cmd.Connection = connection;
cmd.Parameters.AddWithValue("@artistname", alarm.ArtistName);
cmd.Parameters.AddWithValue("@tijd", alarm.Time);
connection.Open();
int a = cmd.ExecuteNonQuery();
System.Windows.Forms.MessageBox.Show(a.ToString());
// returns 1 but database doesn't actually update..
}
The code above is what i'm using to update my database's Alarm table. int a returns a 1 but the database doesn't actually get updated. what am i doing wrong? visual studio doesn't give me any error messages either.
ExecuteNonQuery will return a 1 of successful. You are performing an
INSERT
statement not anUPDATE
statement. If you want to the id of the new record that was added usethen use