更正:上面的adapter.selectcommand应该改为adapter.InsertCommand。

解决方案 »

  1.   

    adapter.update(youdataset);
    语句全都用自动产生的,如果你非要自己写,用IDE托动一个adapter to you form,一步一步完成后看代码.ok
      

  2.   

    先是更改的话应该是updateCommand 然后是INsertCommand
      

  3.   

    adapter.update(youdataset);同意楼上
    adapter的InsertCommand,UpdateCommand,deleteCommad都写
    或着根据行的状态自己写SQL语句去更新
      

  4.   

    SqlConnection cn = new SqlConnection(connectionstring);
    cn.Open();SqlDataAdapter sda = new SqlDataAdapter( "select * from xxx " , cn ); 
    sda.MissingSchemaAction = MissingSchemaAction.AddWithKey;SqlCommandBuilder scb = new SqlCOmmandBuilder( sda );     
    scb.GetUpdateCommand();DataSet ds = new DataSet();
    sda.Fill( ds );ds发生增删改.........sda.Update( ds );
      

  5.   

    updatecommand和insertcommand都要用!
      

  6.   

    不一定updatecommand和insertcommand都使用。只要CommandBuilder.GetUpdateCommand()之后,增删改都可以,表必须有主键
      

  7.   

    CommandBuilder.GetUpdateCommand()用起来较方便,但效率不高
      

  8.   

    呵呵,如果要取效率,可能直接执行command去CRUD最简单了
      

  9.   

    adapter的相关命令属性是用什么先要实例什么
    有修改要 UpdateCommand
    有添加要 insertCommand
    有删除要 DeleteCommand
      

  10.   

    static OleDbCommand CreateDataAdapterUpdateCommand()
    {
    string strSQL,strConn;
    strSQL = "UPDATE [Order Details] SET OrderID = ?,ProductID = ?,Quantity = ?, UnitPrice = ?,Discount = ?"+
    " WHERE OrderID = ? AND ProductID = ? AND Quantity = ? AND UnitPrice = ? AND Discount = ?";
    strConn = "Provider=sqloledb;Data Source=******;Initial Catalog=Northwind;User Id=sa;Password=********;" ;
    OleDbConnection cn = new OleDbConnection(strConn);
    OleDbCommand cmd = new OleDbCommand(strSQL,cn);
    OleDbParameterCollection pc = cmd.Parameters;
    pc.Add("OrderID_New",OleDbType.Integer,0,"OrderID");
    pc.Add("ProductID_New",OleDbType.Integer,0,"ProductID");
    pc.Add("Quantity_New",OleDbType.SmallInt,0,"Quantity");
    pc.Add("UnitPrice_New",OleDbType.Currency,0,"UnitPrice");
    pc.Add("Discount_New",OleDbType.Decimal,0,"Discount"); OleDbParameter param;
    param = pc.Add("OrderID_Orig",OleDbType.Integer,0,"OrderID");
    param.SourceVersion = DataRowVersion.Original;
    param = pc.Add("ProductID_Orig",OleDbType.Integer,0,"ProductID");
    param.SourceVersion = DataRowVersion.Original;
    param = pc.Add("Quantity_Orig",OleDbType.SmallInt,0,"Quantity");
    param.SourceVersion = DataRowVersion.Original;
    param = pc.Add("UnitPrice_Orig",OleDbType.Currency,0,"UnitPrice");
    param.SourceVersion = DataRowVersion.Original;
    param = pc.Add("Discount_Orig",OleDbType.Decimal,0,"Discount");
    param.SourceVersion = DataRowVersion.Original; return cmd;
    } static OleDbCommand CreateDataAdapterInsertCommand()
    {
    string strSQL,strConn;
    strSQL = "INSERT INTO [Order Details](OrderID,ProductID,Quantity,UnitPrice,Discount)"+
     "VALUES(?,?,?,?,?)";
    strConn = "Provider=sqloledb;Data Source=******;Initial Catalog=Northwind;User Id=sa;Password=********;" ;
    OleDbConnection cn = new OleDbConnection(strConn); OleDbCommand cmd = new OleDbCommand(strSQL,cn);
    //OleDbParameterCollection pc = cmd.Parameters;
    cmd.Parameters.Add("OrderID",OleDbType.Integer,0,"OrderID");
    cmd.Parameters.Add("ProductID",OleDbType.Integer,0,"ProductID");
    cmd.Parameters.Add("Quantity",OleDbType.SmallInt,0,"Quantity");
    cmd.Parameters.Add("UnitPrice",OleDbType.Currency,0,"UnitPrice");
    cmd.Parameters.Add("Discount",OleDbType.Decimal,0,"Discount"); return cmd;
    }
      

  11.   

    用dataset其实也蛮方便的,你可以看看我的一个帖子
    http://community.csdn.net/Expert/topic/3436/3436302.xml?temp=.5492517
      

  12.   

    http://blog.csdn.net/zhzuo/archive/2004/08/06/67037.aspx
      

  13.   

    insert会自动更新到数据库去的。而编辑过的dataset要用update来更新。
      

  14.   

    直接使用DataAdaper的updata方法就可以了