用SqlCommandBuilder 大批量修改怎么不行?

时间:2022-05-08 14:53:50
 SqlCommandBuilder builder = new SqlCommandBuilder(data);
 data.Update(ds, "mydt");
怎么用?
现在我一个DatagridView的数据源是DataTable。
但是我要大批量的修改。然后我就考虑到了SqlCommandBuilder 。

但是好像行不通?

分析:

1、使用SqlCommandBuilder生成sql语然必须保证表有主键。否则自己写sql语句


string connString="你的连接字符串";
SqlConnection conn=new SqlConnection(connString);
conn.Open();
SqlDataAdapter adp = new SqlDataAdapter("select * from table",conn);
SqlCommandBuilder builder = new SqlCommandBuilder(adp);
adp.Update(dt);


2、string connString="你的连接字符串";
SqlConnection conn=new SqlConnection(connString);
conn.Open();
SqlDataAdapter adp = new SqlDataAdapter("select * from table",conn);
SqlCommandBuilder builder = new SqlCommandBuilder(adp);
adp.Update(dt); 
adp.Dispose();