How do I delete records using data reader?

The procedure for updating records using INSERT commands is very similar to the one we presented in the previous example (of SELECT) except that here the command does not return anything and thus the method to call on the SqlCommand object is called ExecuteNonQuery().

C# Version
	string connString = "server=FARAZ; database=programmersheaven;" +
				  "uid=sa; pwd=";
	SqlConnection conn = new SqlConnection(connString);
			
	// DELETE Query
	string cmdString =  "DELETE FROM Author " + 
				"WHERE authorId = 3";
	SqlCommand cmd = new SqlCommand(cmdString, conn);
	conn.Open();
	cmd.ExecuteNonQuery();
	conn.Close();


VB.Net Version
        Dim connString As String = "server=FARAZ; database=programmersheaven;" + _
                                   "uid=sa; pwd="
        Dim conn As New SqlConnection(connString)
        ' DELETE Query
        Dim cmdString As String =  "DELETE FROM Author " + 
                                   "WHERE authorId = 3"
        Dim cmd As New SqlCommand(cmdString, conn)
        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()


Back

 
Printer friendly version of the FAQ-ADONET-Delete-Using-Data-Reader page


Sponsored links

Check For Updates
Easily add update features to your applications. A complete .Net updating solution.
Build IT Knowledge with Current & Trusted Content
Helps Employees Develop & Hone New Technical Programming Skills. Sign Up & Get Full Access.
Check Out IT Certification Preparation Materials
Sign Up With SkillSoft & Get Access to Training Materials for Over 50 Professional Certifications.
Online Crash Analysis
Automatically capture customer crash data, no debugger required. Support for .NET, C++, OS X, Java.
.Net Localization Tool Sisulizer
Localize your .Net apps: ResX and assemblies. Database, XML & HTML Help localization. Try Sisulizer!

Advertisement



Free Magazine

Free Magazines
eWeek The essential technology information source for builders of e-business.... subscribe now

Newsletter | Submit Content | About | Advertising | Awards | Contact Us | Link to us |
© 1996-2008 Community Networks Ltd All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Synchron Data - .NET development.