Wednesday, November 22, 2017

Error while reading an excel file as a sql table-'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine

Im having a xlsx  file which contain some data as on the below image and i need to read them and store as a SQL data table or as an string array.

So any how my ultimate goal is to read the data from a excel file.

But i got this stupid error.

'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine'



string path = @"C:\temp\GOSTestDetails.xlsx";
            string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;";

            string[] DashboardName = new string[100];
            int i = 0;
            int j = 0;
using (OleDbConnection connection = new OleDbConnection(connStr))
            {
                connection.Open();
                OleDbCommand command = new OleDbCommand("select * from [TestDetails$]", connection);
using (OleDbDataReader dr = command.ExecuteReader())
                {
                    dr.NextResult();
                    for ( j = 0; j < dr.FieldCount; j++)
                    {
                        
                        var row1Col0 = dr[j];
                           
                            DashboardName[i++] =                    row1Col0.ToString();
                    }

                }
            }
        }

So the solution is to download and install 

Microsoft Access Database Engine 2010 Redistributable.



No comments:

Post a Comment