make sure your table has a primary key, tryOleDbCommandBuilder cb = new OleDbCommandBuilder(oleDbDataAdapter1);
oleDbDataAdapter1.Update(m_set,"test");

解决方案 »

  1.   

    看看你的oledbdataAdapter1的 SelectCommand 属性,应该是因为该属性的select语句中不包含表的关键字列,所以无法动态生成updatacommand属性的sql语句!必须包含关键字,才可以动态生成!:)
      

  2.   

    我的SQL语句是写的SELECT * .......,怎么回不包含关键字列,INSERT INTO 都可以完成
      

  3.   

    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");

    }
    抛出异常
      

  4.   

    要使用CommandBuilder,一定要操作的表中设置主键(primary key)。
    否则就会出现“对于不返回任何键列信息的 SelectCommand 不支持 UpdateCommand 的动态 SQL 生成。”这个提示!