好先生之我是陆远小说:关于ADO.net问题(如何更新ACCESS表!)

来源:百度文库 编辑:高考问答 时间:2024/05/02 06:47:21
语言用是的C#
private void button1_Click(object sender, System.EventArgs e)
{
OleDbCommandBuilder cmdb=new OleDbCommandBuilder(ad);
if(ds.HasChanges())
{
ad.Update(ds,"pz");
MessageBox.Show("OK!");
}

}

private void button2_Click(object sender, System.EventArgs e)
{
string constr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=config.mdb;";
string cmdstr="select * from pz";
con.ConnectionString=constr;
cmd.Connection=con;
cmd.CommandText=cmdstr;
ad.SelectCommand=cmd;
ds.Clear();
ad.Fill(ds,"pz");
dg.SetDataBinding(ds,"pz");
}
//////////////说明
private System.Data.OleDb.OleDbDataAdapter ad;
private System.Data.DataSet ds;
private System.Data.OleDb.OleDbCommand cmd;
private System.Windows.Forms.DataGrid dg;
////////////
我在更新的时候会出错,出错信息如下:

Update requires the UpdateCommand to have a connection object. The Connection property of the UpdateCommand has not been initialized.
////////////////我试过了,如果不用OLEDB,用SQL连接MS SQL就没有问题,请高手明示!