ADO.net的更新问题,急!!!! make sure your table has a primary key, tryOleDbCommandBuilder cb = new OleDbCommandBuilder(oleDbDataAdapter1);oleDbDataAdapter1.Update(m_set,"test"); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 看看你的oledbdataAdapter1的 SelectCommand 属性,应该是因为该属性的select语句中不包含表的关键字列,所以无法动态生成updatacommand属性的sql语句!必须包含关键字,才可以动态生成!:) 我的SQL语句是写的SELECT * .......,怎么回不包含关键字列,INSERT INTO 都可以完成 oleDbDataAdapter1.SelectCommand.CommandText=String.Format("select * from {0} where 0=1",tablestr); OleDbCommandBuilder cmdb=new OleDbCommandBuilder(oleDbDataAdapter1); oleDbDataAdapter1.Fill(m_set,tablestr); DataRow row=m_set.Tables[tablestr].NewRow(); for (int i=0;i<m_set.Tables[tablestr].Columns.Count;i++) { if(grid.GetData(i+1,"Value")!=null) row[i]=grid.GetData(i+1,"Value"); } //row.AcceptChanges(); m_set.Tables[tablestr].Rows.Add (row);上边代码执行OK;oleDbDataAdapter1.SelectCommand.CommandText =String.Format("select * from {0} where {1}",tablestr,wherestr); oleDbDataAdapter1.Fill(m_set,tablestr);OleDbCommandBuilder cmdb=new OleDbCommandBuilder(oleDbDataAdapter1); //oleDbDataAdapter1.Fill(m_set,tablestr); for (int i=0;i<m_set.Tables[tablestr].Columns.Count;i++) { if((grid.GetData(i+1,"Value")!=null)&&(grid.Rows[i+1].AllowEditing==true) ) m_set.Tables[tablestr].Rows[0][i]=grid.GetData(i+1,"Value"); }抛出异常 要使用CommandBuilder,一定要操作的表中设置主键(primary key)。否则就会出现“对于不返回任何键列信息的 SelectCommand 不支持 UpdateCommand 的动态 SQL 生成。”这个提示! c#运行错误 C# 怎样调用带序号的存储过程 漂亮的二级菜单样式,进来。。。。 如何 获得 本机 的网卡地址 Master页面 怎么调用 Content页面 的一个过程或都函数啊? dataset数据更改事件 运行时动态切换窗口ICON图标,到底有多少种方法?50分 求宝贵意见!谢谢谢谢谢谢 程序不能以其他帐号运行 c#中的循环 谁有c#编写的c/s结构的原代码,学习用,我还会加分哦,谢谢大家 如何實現project里面的甘特圖?提供資料,控件,思路的都好! 能否用c#开发activeX控件否?
OleDbCommandBuilder cmdb=new OleDbCommandBuilder(oleDbDataAdapter1);
oleDbDataAdapter1.Fill(m_set,tablestr);
DataRow row=m_set.Tables[tablestr].NewRow();
for (int i=0;i<m_set.Tables[tablestr].Columns.Count;i++)
{
if(grid.GetData(i+1,"Value")!=null)
row[i]=grid.GetData(i+1,"Value");
}
//row.AcceptChanges();
m_set.Tables[tablestr].Rows.Add (row);上边代码执行OK;
oleDbDataAdapter1.SelectCommand.CommandText =String.Format("select * from {0} where {1}",tablestr,wherestr);
oleDbDataAdapter1.Fill(m_set,tablestr);
OleDbCommandBuilder cmdb=new OleDbCommandBuilder(oleDbDataAdapter1); //oleDbDataAdapter1.Fill(m_set,tablestr);
for (int i=0;i<m_set.Tables[tablestr].Columns.Count;i++)
{
if((grid.GetData(i+1,"Value")!=null)&&(grid.Rows[i+1].AllowEditing==true) )
m_set.Tables[tablestr].Rows[0][i]=grid.GetData(i+1,"Value");
}
抛出异常
否则就会出现“对于不返回任何键列信息的 SelectCommand 不支持 UpdateCommand 的动态 SQL 生成。”这个提示!