1
votes

I had an old Project which ran fine. Now I am getting the error while trying to import from Excel:

enter image description here

System.Invalidoperationexception the 'microsoft.jet.oledb.4.0' provider is not registered

I am able to login. I tried changing platform of project to x86/x64/Any CPU but no use. I have also changed:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source

To

Provider=Microsoft.Jet.OLEDB.12.0;Data Source

But no use. Here's my code for importing Excel:

 private void button1_Click_1(object sender, EventArgs e)
    {
      //  string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\BILL REGISTER 97.xls;Extended Properties=\"Excel 8.0;HDR=Yes;\";";
        //string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + txtfilepath.Text + ";Extended Properties=\"Excel 8.0;HDR=Yes;\";";
        string connStr = "Provider=Microsoft.Jet.OLEDB.12.0;Data Source=" + txtfilepath.Text + ";Extended Properties=\"Excel 8.0;HDR=Yes;\";";


        OleDbConnection con = new OleDbConnection(connStr);
       // string strCmd = "select * from [sheet1$A8:P10]";
       // string strCmd = "select * from [sheet1$A8:IV65536]";
        string strCmd = "select * from [sheet1$A6:IV65536]";
        OleDbCommand cmd = new OleDbCommand(strCmd, con);
        try
        {
            con.Open();
            ds.Clear();
            da.SelectCommand = cmd;
            da.Fill(ds);
            dataGridView1.DataSource = ds.Tables[0];
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
        finally
        {
            con.Close();
        }
    }

I have installed Office2010.

1
Which version of Office? 64bit or 32bit?Steve
How can I check that ?mark
If Office is 32bit then you should use the ACE.12.0 and compile your app for x86. (Or AnyCPU with prefer 32bit) Look at this answer it could help understand the situation stackoverflow.com/questions/17716207/…Steve

1 Answers

2
votes

Try using

Provider=Microsoft.ACE.OLEDB.12.0;Data Source

Instead of

Provider=Microsoft.Jet.OLEDB.12.0;Data Source