Love this site? Hate it? Leave us some comments.
*/

Other Views

corner
*/

ADONET FAQ - Inserting Records Using Data Reader

How do I insert 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);
			
	// INSERT Query
	string cmdString ="INSERT INTO Author " +
				"(authorId, name) " +
				"VALUES(3, 'Anders Hejlsberg')";
			
	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)
        ' INSERT Query
        Dim cmdString As String = "INSERT INTO Author " + _
                                  "(authorId, name) " + _
                                  "VALUES(3, 'Anders Hejlsberg')"
        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