你应该把
SqlCommandBuilder custCB=new SqlCommandBuilder(this.sqlDataAdapter1);
放在
private void showtable()中。
SqlCommandBuilder custCB=new SqlCommandBuilder(this.sqlDataAdapter1);
放在
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);
}
xumahua(xumahua) :只是把前三行改了个形式吧,代码和我原来那个一样啊
OleDbCommandBuilder Builder=new OleDbCommandBuilder(Adapter);
Adapter.Fill(this.dataSetSubItem,"SubItem");
如果你改一下。
this.sqlDataAdapter1.SelectCommand=new SqlCommand(commandtext,this.sqlConnection1); 《---------
this.sqlDataAdapter1.UpdateCommand = null;〈--------------
你的updatacommnd肯定不为空,所以用SqlCommandBuilder也没有用!