Library code snippets
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();
Related articles
Related discussion
-
High-Performance .NET Application Development & Architecture
by Manjot Bawa (0 replies)
-
PrintDocument printing using DOS print
by squrrel (1 replies)
-
hey developers out there
by pitsophera (0 replies)
-
Looking for .Net C# Software Developers
by sugagirisa (2 replies)
-
LINQ in Action
by naser1 (0 replies)
Related podcasts
-
A Practical Look at Silverlight 2 Part 1
Now that Silverlight 2 is at the Olympics and making a big splash, we wanted to explore this fascinating technology more. Microsoft Silverlight 2 is a cross-browser, cross-platform, and cross-device plug-in for delivering the next generation of .NET based media experiences and rich interactive ap...
Events coming up
-
Mar
15
DevWeek 2010
London, United Kingdom
DevWeek is Europe’s leading independent conference for software developers, database professionals and IT architects, and features expert speakers on a wide range of topics, including .NET 4.0, Silverlight 3, WCF 4, Visual Studio 2010, REST, Windows Workflow 4, Thread Synchronization, ASP.NET 4.0, SQL Server 2008 R2, LINQ, Unit Testing, CLR & C# 4.0, .NET Patterns, WPF 4, F#, Windows Azure, ADO.NET, Entity Framework, Debugging, T-SQL Tips & Tricks, and more.
very basic. kindly request not to put this much basic article in this spectacular site
This thread is for discussions of How to delete records with SqlCommand.