在c#中将数据行添加到数据表中 [英] Adding datarow to datatable in c# ..
问题描述
嘿,任何人都可以帮我解释下面的代码......并解释一下,并解释一下命令构建器的用法吗?
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);
行发生异常:da.Update(ds);
当传递带有新行的DataRow集合时,更新需要有效的InsertCommand。
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.
推荐答案
查看下面的链接...
使用DataSet-and-DataAdapter插入关系数据
[ ^ ]
问候,
RK
Hi,
Check the Link below...
Inserting-relational-data-using-DataSet-and-DataAdapter
[^]
Regards,
RK
大家好/>
运行此代码
SqlDataAdapter da = new SqlDataAdapter(select * from item,con);
con 。打开();
试试
{
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();
问候,
Pawan
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
这篇关于在c#中将数据行添加到数据表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!