Update From Dataset ADO.Net

Sunday, July 4, 2010


he System.Data namespace consists mostly of the classes that constitute the ADO.NET architecture. The ADO.NET architecture enables you to build components that efficiently manage data from multiple data sources. In a disconnected scenario (such as the Internet), ADO.NET provides the tools to request, update, and reconcile data in multiple tier systems.

//Initialize Connection from database

SqlConnection cn = new SqlConnection("connectionString");

//add this Query command with connectionstring parameters to data adopter to get schema form database

SqlDataAdapter da = new SqlDataAdapter("Select * from tablename",cn);

// Dataset Object

DataSet ds = new DataSet();

//fill database schema to dataset

da.FillSchema(ds, SchemaType.Mapped);


DataRow dRow1 = ds.Tables["workers"].NewRow();

dRow1[1] = "Value1"; //textBox1.Text;

dRow1[2] ="Value2"; //textBox2.Text;

dRow1[3] ="Value3";///textBox3.Text;

dRow1[4] = "Value4";///textBox4.Text;

dRow1[5] = "Value5";//textBox5.Text;

ds.Tables["workers"].Rows.Add(dRow1);

SqlCommandBuilder builder = new SqlCommandBuilder(da);

da.Update(ds);

ds.AcceptChanges();

share this post
Share to Facebook Share to Twitter Share to Google+ Share to Stumble Upon Share to Evernote Share to Blogger Share to Email Share to Yahoo Messenger More...

0 comments: