Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 14,404 times

Related Categories

How to delete records with SqlCommand

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();

Edward Tanguay updates his personal web site tanguay.info weekly with code, links, quotes and thoughts on web development. Sign up for the free newsletter.

Comments

  • very basic

    Posted by parimalapriya on 29 Apr 2004

    very basic. kindly request not to put this much basic article in this spectacular site