SqlDataAdapter的易错用法

来源:互联网 发布:网络推广需要多少钱 编辑:程序博客网 时间:2024/04/29 06:14
strsql = "select id as'方案编号',prereagentid as '试剂编号' ,prereagent as '试剂名称',preamount as '试剂用量'  
from project where id = (select Max(id)+1 from remarks)";this.myconn = new SqlConnection(strconn);this.da = new SqlDataAdapter(strsql, strconn);this.ds = new DataSet();da.Fill(ds, "data");
SqlCommandBuilder bd = new SqlCommandBuilder(da);
da.InsertCommand = bd.GetInsertCommand();  
da.Update(ds.Tables["data"]);//以上代码,如果稍不留神,就会忽略掉data名称,程序便出错。也就是说,如果写成 da.Fill(ds);……da.Update(ds);//就必然会出错,必须得有表名。


原创粉丝点击