使用dataset更新行后用commandbuilder不能更新;(附源码和错误信息,请高手帮忙解答!)
glgzx 2005-08-21 11:39:23 未处理的“System.InvalidOperationException”类型的异常出现在 system.data.dll 中。
其他信息: 对于不返回任何键列信息的 SelectCommand 不支持 UpdateCommand 的动态 SQL 生成。
*************************************
上面为报错信息;下面为源代码
*************************************
SqlConnection thisConnection=new SqlConnection( @"Server=30.5.20.15;"+
"user id=myuser;"+
"password=myok;"+
"Connection Timeout=10;"+
"Database=shly;");
SqlDataAdapter da =new SqlDataAdapter ();
da.SelectCommand =new SqlCommand ("select * from mytable",thisConnection);
DataSet ds =new DataSet ();
da.Fill (ds,"mytable");
DataTable dt=ds.Tables ["mytable"];
dt.Rows [0]["firstName"]="JuLian";
SqlCommandBuilder sqlCb=new SqlCommandBuilder (da);
da.Update (ds,"mytable");