初始化字符串的格式不符合从索引121开始的规范
本文关键字:开始 索引 字符串 格式 不符合 初始化 | 更新日期: 2023-09-27 18:17:12
在这个按钮上,点击它应该加载一个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];
}
}
按如下所示更新值,这将修复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;");