Written some cool source code? Upload it to Programmer's Heaven.
*/

Other Views

corner
*/

ADONET FAQ - Inserting a Record in a Table Using Dataset

How do I insert a record in the table using ADO.Net dataset?

To insert a record in the data table, you create an object of the DataRow using the DataTable object. Then you set the appropriate field values and finally add it to the DataTable’s Rows collection.

C# Version
DataTable dt = ds.Tables["Article"];
			
// Insert 
DataRow dr = dt.NewRow();
dr[0] = 4;
dr[1] = "MFC Programming";
dr[2] = "VC++ MFC Library";
dr[3] = 3;
dr[4] = 3000;
dr[5] = DateTime.Parse("8/14/1999");
dt.Rows.Add(dr);
da.Update(ds, "Article");
ds.AcceptChanges();


VB.Net Version
Dim dt As DataTable
dt = ds.Tables("Article")
' Insert 
Dim dr As DataRow
dr = dt.NewRow()
dr(0) = 4
dr(1) = "MFC Programming"
dr(2) = "VC++ MFC Library"
dr(3) = 3
dr(4) = 3000
dr(5) = DateTime.Parse("8/14/1999")
dt.Rows.Add(dr)
da.Update(ds, "Article")
ds.AcceptChanges()


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