On this button click it should load the contents of an excel file into a dataGrid but instead am getting the error mentioned in the title of this post. What is it that am doing wrong?
在这个按钮上,它应该将一个excel文件的内容加载到dataGrid中,但是却得到了这个帖子标题中提到的错误。我做错了什么?
private void button7_Click_2(object sender, EventArgs e)
{
string path = "C:\\Users\\jdavis\\Downloads\\Pharmacies\\CrossReferencing v3\\CrossReferencing\\\bin\\Debug\\cross_check.xls";
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + path + ";Extended Properties=' Excel 8.0;HDR=Yes;IMEX=1;';");
OleDbCommand command = new OleDbCommand
(
"SELECT"+"FROM [cross_check]",con
);
DataSet cross = new DataSet();
OleDbDataAdapter adapter = new OleDbDataAdapter(command);
adapter.Fill(cross);
dataGridView2.DataSource = cross.Tables[0];
}
}
1 个解决方案
#1
1
Update the values as shown below, and this will get the ISAM and formatting issues fixed.
更新如下所示的值,这将修复ISAM和格式化问题。
string path = " \"C:\\Users\\jdavis\\Downloads\\Pharmacies\\CrossReferencing v3\\CrossReferencing\\bin\\Debug\\cross_check.xls\" ";
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" + path + ";Extended Properties= Excel 8.0;IMEX=1;");
#1
1
Update the values as shown below, and this will get the ISAM and formatting issues fixed.
更新如下所示的值,这将修复ISAM和格式化问题。
string path = " \"C:\\Users\\jdavis\\Downloads\\Pharmacies\\CrossReferencing v3\\CrossReferencing\\bin\\Debug\\cross_check.xls\" ";
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" + path + ";Extended Properties= Excel 8.0;IMEX=1;");