Jevon Jevon - 1 year ago 130
C# Question

Format of the initialization string does not conform to specification starting at index 121

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?

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);
dataGridView2.DataSource = cross.Tables[0];


Answer Source

Update the values as shown below, and this will get the ISAM and formatting issues fixed.

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;");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download