This code shows you how to delete records with an SQL statement and get the number of records deleted returned back as an integer.
SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["con"]);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "DELETE FROM EmployeesCopy WHERE TitleofCourtesy='Mr.'";
cmd.Connection = con;
con.Open();
int numberDeleted = cmd.ExecuteNonQuery();
Response.Write(numberDeleted.ToString() + " employees were deleted.<br>");
// use this instead of the above line if we're in a windows form rather than an ASP.NET page
//MessageBox.Show(numberDeleted.ToString() + " employees were deleted.<br>");
con.Close();
Comments