0

大家好,我正在尝试通过带有按钮的 datagridview 将数据保存到数据库,但每次运行应用程序时都会出现以下错误,这是我的代码:

        DataTable Table = new DataTable(); 
        BindingSource bindingSource1 = new BindingSource();
 string connetionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Database/Database.accdb;";
        string sql = "SELECT * FROM IAE;";
        OleDbConnection connection = new OleDbConnection(connetionString);
        OleDbDataAdapter dataadapter = new OleDbDataAdapter(sql, connection);
        OleDbCommandBuilder cb = new OleDbCommandBuilder(dataadapter);
        DataSet ds = new DataSet();
        connection.Open();
        dataGridView1.DataSource = ds.Tables["IAE"];
        dataadapter.Update((DataTable)bindingSource1.DataSource);
        connection.Close();

错误:值不能为空。参数名称:数据表

需要你的帮助和感谢

4

1 回答 1

0

Reason of error is your bindingSource1.DataSource property is NULL. Your are not assigning any DATASOURCE to your bindingsource class

于 2012-09-08T19:55:16.773 回答