1

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



    }
}
Javy26
  • 375
  • 1
  • 7
  • 22

1 Answers1

1

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;");
vipersassassin
  • 178
  • 2
  • 10