Export DataTable to Excel Error: The Microsoft.Jet.OLEDB.4.0 provider is not registered on the local machine

Last Reply 5 months ago By dharmendr

Posted 5 months ago

I am getting the following error:

An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.dll

Additional information: The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine.

https://ibb.co/zNd8rsF 

This is a window based application. I am trying to upload the excel file.i Have the following code: 

string excelConnectionString=null;
if (fileExtension == ".xls")
{
    excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename + ";Extended Properties=Excel 5.0";
}
//connection String for xlsx file format.
else if (fileExtension == "xlsx")
{
    excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
    filename + ";Extended Properties=Excel 12.0";
}

ExcelConnection = new OleDbConnection(excelConnectionString);             
string ExcelQuery = "Select * from [Sheet1$] where [companyname] IS NOT NULL or [website] IS NOT NULL or [country] IS NOT NULL ";       // from Sheet1";                  
ds = new DataSet();
da = new OleDbDataAdapter(ExcelQuery, ExcelConnection);
da.Fill(ds, "TEMP");
DataTable tblWithBadEml = ds.Tables["TEMP"];