我正在从这个Link将excel数据导入dataGridView。但我收到错误“对象引用未设置为对象的实例”。
String name = "Sheet1";
String constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
file +
";Extended Properties='Excel 8.0;HDR=YES;';";
OleDbConnection con = new OleDbConnection(constr);
OleDbCommand oconn = new OleDbCommand("Select * From [" + name + "$]", con);
con.Open();
OleDbDataAdapter sda = new OleDbDataAdapter(oconn);
System.Data.DataTable data = new System.Data.DataTable();
sda.Fill(data);
dgvIM.DataSource = data;
答案 0 :(得分:0)
调试时检查dgvIM的值。它可能是空的;