你应该把
SqlCommandBuilder custCB=new SqlCommandBuilder(this.sqlDataAdapter1);
放在
private void showtable()中。

解决方案 »

  1.   

    private void showtable(){
             
            string sql="select * from tablename";        sqlDataAdapter1 sqlDataAdapter1=new sqlDataAdapter(sql,sqlConnection1);
            this.dataSet1.Clear();        this.sqlDataAdapter1.Fill(this.dataSet1,this.tablename);
            
            this.dataGrid1.SetDataBinding(this.dataSet1,this.tablename);        this.dataGrid1.Visible =true;        this.update.Visible=true;}
    private void update_Click(object sender, System.EventArgs e){
         
         SqlCommandBuilder custCB=new SqlCommandBuilder(this.sqlDataAdapter1);
         this.sqlDataAdapter1.Update(this.dataSet1,this.tablename);
                     
    }
      

  2.   

    Knight94:似乎不是这个的原因啊,改了还是不行
     xumahua(xumahua) :只是把前三行改了个形式吧,代码和我原来那个一样啊
      

  3.   

    OleDbDataAdapter Adapter=new OleDbDataAdapter(commandtext,this.oleDbConnection1);
    OleDbCommandBuilder Builder=new OleDbCommandBuilder(Adapter);
    Adapter.Fill(this.dataSetSubItem,"SubItem");
      

  4.   

    SqlCommandBuilder 只是生成其他任何未设置的 Transact-SQL 语句。
    如果你改一下。
    this.sqlDataAdapter1.SelectCommand=new SqlCommand(commandtext,this.sqlConnection1);    《---------
    this.sqlDataAdapter1.UpdateCommand = null;〈--------------
    你的updatacommnd肯定不为空,所以用SqlCommandBuilder也没有用!
      

  5.   

    InsertCommand 和DeleteCommand 同样!
      

  6.   

    to SWLYX (阿南) : 一样吗?你为什么不试试呢?faint!