大家好我想通过带有按钮的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();
错误:值不能为空。参数名称:dataTable
需要你的帮助和谢谢
答案 0 :(得分:0)
错误原因是您的bindingSource1.DataSource属性为NULL。您没有将任何DATASOURCE分配给您的bindingsource类