Is it possible in C# / ASP.NET to know if the ExecuteNonQuery
inserted a record or not?
I am checking to make sure the email address does not exist in the table using a subquery.
Is there a way to know if an Insert was made in ASP.NET?
CommandPrizeEmails.Parameters.Add("@Email", SqlDbType.VarChar, 50);
CommandPrizeEmails.Parameters.Add("@DateToday", SqlDbType.DateTime);
CommandPrizeEmails.Parameters["@Email"].Value = txtEmail.Text;
CommandPrizeEmails.Parameters["@DateToday"].Value = DateTime.Now;
CommandPrizeEmails.ExecuteNonQuery();
//int newID = (int)CommandPrizeEmails.ExecuteScalar();
//CommandPrizeEmails.ExecuteNonQuery();
//if (newID >= 1) {
// divSuccesfulEntry.Visible = true;
//} else {
// divRepeatEntry.Visible = true;
//}
You can get the rows affected in return to verify the process.
http://blogs.msdn.com/b/spike/archive/2009/01/27/sqlcommand-executenonquery-returns-1-when-doing-insert-update-delete.aspx