Got something to write about? Check out our Article Builder.
*/

Other Views

corner
*/

ADONET FAQ - Updating Records Using Data Reader

How do I update 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);
			
	// UPDATE Query
	string cmdString =  "UPDATE Author " +
				"SET name = 'Grady Booch' " + 
				"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)
        ' UPDATE Query
        Dim cmdString As String =  "UPDATE Author " + _
                                   "SET name = 'Grady Booch' " + _
                                   "WHERE authorId = 3"
        Dim cmd As New SqlCommand(cmdString, conn)
        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()


Back
corner
© 1996-2008 CommunityHeaven LLC. 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 our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.
Resource Listings