I had an old Project which ran fine. Now I am getting the error while trying to import from Excel:
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.