Import Excel C # OleDB

0

Friends, I have an exception when importing Excel;

[error]

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

[Code]

 string conStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0;HDR={1};TypeGuessRows=0;ImportMixedTypes=Text;Imex=1;""";

            conStr = String.Format(conStr, pathFile, "Yes");
            OleDbConnection connExcel = new OleDbConnection(conStr);
            OleDbCommand cmdExcel = new OleDbCommand();
            OleDbDataAdapter oda = new OleDbDataAdapter();
            DataTable dt = new DataTable();
            cmdExcel.Connection = connExcel;

            connExcel.Open(); //explodi o erro aqui 
    
asked by anonymous 08.11.2017 / 15:01

2 answers

2

You must install 2007 Office System Driver: Data Connectivity Components in machine for this provider to work.

    
08.11.2017 / 15:52
0

I changed to:

string conStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=""Excel 8.0;HDR={1};TypeGuessRows=0;ImportMixedTypes=Text;Imex=1;""";

return error:

Unexpected error caused by external database drivers (1).

    
08.11.2017 / 19:21