0

EL problema es que al momento de cargar el archivo xlsx, me sale el error de "El proveedor "Microsoft.ACE.OLEDB.12.0" no está registrado en el equipo local"; aunque si tengo instalado este componente en la maquina. Ademas he cambiado la opcion de "any cpu" a "x86" y el problema persiste.

saben de alguna otra opcion? o como cargar el "xlsx" de otra manera a un gridview. a continuacion el codigo:

protected void Benvarch_Click(object sender, EventArgs e)
        {
            string connectionString = "";
            if (fuarchivo.HasFile) {

                string fileName = Path.GetFileName(fuarchivo.PostedFile.FileName);
                string fileExtension = Path.GetExtension(fuarchivo.PostedFile.FileName);
                string fileLocation = Server.MapPath("~/App_Data/" + fileName);
                fuarchivo.SaveAs(fileLocation);
                //Check whether file extension is xls or xslx
                if (fileExtension == ".xls")
                {

                    connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";





                }
                else if (fileExtension == ".xlsx") {

                    connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";

                }

                //Create OleDB Connection and OleDb Command
                OleDbConnection con = new OleDbConnection(connectionString);
                OleDbCommand cmd = new OleDbCommand();
                cmd.CommandType = System.Data.CommandType.Text;
                cmd.Connection = con;
                OleDbDataAdapter dAdapter = new OleDbDataAdapter(cmd);
                DataTable dtExcelRecords = new DataTable();
                con.Open();
                DataTable dtExcelSheetName = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                string getExcelSheetName = dtExcelSheetName.Rows[0]["Table_Name"].ToString();
                cmd.CommandText = "SELECT * FROM [" + getExcelSheetName + "]";
                dAdapter.SelectCommand = cmd;
                dAdapter.Fill(dtExcelRecords);
                con.Close();
                gvcarga.DataSource = dtExcelRecords;
                gvcarga.DataBind();


            }


        }

1 respuesta 1

0

Cuando tienes ese error es porque debes instalar el redistribuible de ACE.OLEDB.12

Lo descargas de aqui

Microsoft Access Database Engine 2010 Redistributable

aqui se menciona mas sobre el problema

Installing the Microsoft.ACE.OLEDB.12.0 Provider for Both 64-bit and 32-bit Processing

Si quieres una alternativa para trabajar el excel podrias usar una libreria basada en open xml como ser ClosedXML

ClosedXML nuget

algo como esto

using (XLWorkbook workBook = new XLWorkbook(filePath))
{
    //Read the first Sheet from Excel file.
    IXLWorksheet workSheet = workBook.Worksheet(1);

para acceder al worksheet

Read and import Excel file data to DataGridView using ClosedXml using C# and VB.Net

2
  • el redistributibe esta instalado, pero no lo reconoce :( ... sin embargo voy a mirar la otra opcion que me diste.. el 22 feb. 2019 a las 17:12
  • que este instalado y no lo reconozca es algo raro, despues de instalarlo reniciaste la pc ? a veces eso afecta en este tipo de componentes el 22 feb. 2019 a las 17:47

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.