MS Access 2013“对象引用未设置为对象的实例。”

时间:2016-08-18 16:37:45

标签: c# database visual-studio ms-access

我尝试使用此代码从ms访问datagridview

写入数据
try
{
    string strProvider = @"Provider = Microsoft.ACE.OLEDB.12.0; Data Source = Database.accdb";
    string strSql = "Select * from Category";
    OleDbConnection con = new OleDbConnection(strProvider);
    con.Open();
    OleDbCommand cmd = new OleDbCommand(strSql, con);
    OleDbDataAdapter da = new OleDbDataAdapter(cmd);
    DataTable dt = new DataTable();
    da.Fill(dt);
    dgw.DataSource = dt;
}
catch (Exception ex)
{
    Console.WriteLine(ex.ToString());
}

但我收到了这个错误:

System.NullReferenceException: Object reference not set to an instance of an object.

0 个答案:

没有答案