Click here to Skip to main content
15,889,403 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey can anyone help me in the exaption of the following code... and explain me , and explain the use of command builder??




SqlDataAdapter da = new SqlDataAdapter("Select * from mytable", SqlConnection);

DataSet ds = new DataSet();
da.Fill(ds);

DataRow row1 = ds.Tables[0].NewRow();

row1["ID"] = 1;
row1["Name"] = "XYZ";

ds.Tables[0].Rows.Add(row1);

da.Update(ds);



Exception occurrs at the line : da.Update(ds);

Update requires a valid InsertCommand when passed DataRow collection with new rows.
Posted

Hi,

Check the Link below...


Inserting-relational-data-using-DataSet-and-DataAdapter
[^]

Regards,
RK
 
Share this answer
 
Hi All
Run this code

SqlDataAdapter da = new SqlDataAdapter("select * from item ", con);
con.Open();
try
{
DataSet ds = new DataSet();
da.Fill(ds);
SqlCommandBuilder cb = new SqlCommandBuilder(da);




DataRow row1 = ds.Tables[0].NewRow();

row1[0] = txtaccno.Text;
row1[1] = txtname.Text;
row1[2] = txtsalary.Text;
ds.Tables[0].Rows.Add(row1);
da.Update(ds);
gvShow.DataSource = ds;
gvShow.DataBind();

Regards,
Pawan
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900