Click here to Skip to main content
15,901,001 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
Note it is windows application.

I upload excel file.when i read excel file, its show error as follows

the 'microsoft.ace.oledb.12.0' provider is not registered on the local machine"


i uses following code read excel file as follows


C#
Private void import()
{
    String Pathname = txtFileName.Text;
    OleDbConnection conn = new OleDbConnection();
    conn.ConnectionString = @"Provider=Microsoft.ACE.OLEB.12.0;Data Source = '" + Pathname + "'" + @";Extender Properties=""Excel 8.0;HDR=YES;IMEX=1;ImportMIxedTypes=Text;TypeGuessRows=0""";
    conn.Open();
    
    GSheetName = "";
    DataTable dt = conn.GetSchema("Tables");
    string sheetname = "";
    foreach (DataRow row in dt.Rows)
    {
        sheetname = (string)row["TABLE_NAME"];
        if (sheetname.EndsWith("$"))
        {
            GSheetName = sheetname.ToString().Trim();
            break;
        }
    }
    LblSheetName.Text = "Sheet Name :" + GSheetName.ToString().Trim();
    
    if (GSheetName == "" || GSheetName == null)
    {
        progressBar1.Visible = false;
        MessageBox.Show("Invalid Sheet Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
        return;
    }
    
    OleDbCommand command = new OleDbCommand("SELECT * From[" + GSheetName + "]", conn);
    DataSet ds = new DataSet();
    OleDbDataAdapter adapter = new OleDbDataAdapter(command);
    adapter.Fill(ds);
    dataGridView1.DataSource = ds.Tables[0];
    progressBar1.Visible = false;
    }
}

when i upload a excel file error as follows;

the 'microsoft.ace.oledb.12.0' provider is not registered on the local machine".


please help me.

Regards,
Narasiman P
Posted
Updated 6-Jun-13 22:18pm
v3
Comments
Prasad Khandekar 7-Jun-13 4:16am    
Hello Narasiman,

The error "'microsoft.ace.oledb.12.0' provider is not registered on the local machine" is pretty much self-explanatory. isn't it. Try downloading the provide from (http://www.microsoft.com/en-us/download/details.aspx?id=13255) and installing it.

Regards,
Richard MacCutchan 7-Jun-13 4:17am    
The message tells you exactly what the problem is; you have not loaded the ACE driver onto the machine where you are trying to read the Excel file.

Well, you need to download and install it.

Refer the link below to download the driver.
2007 Office System Driver: Data Connectivity Components[^]


--Amit
 
Share this answer
 
C#
String ProviderExcel = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=";
String ExtendedPropertiesExcel = "Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\"";
String connString = ProviderExcel + filePath + ";" + ExtendedPropertiesExcel;
System.Data.OleDb.OleDbConnection cn = new System.Data.OleDb.OleDbConnection(connString);
  try
  {
    cn.Open();
    DataTable schemaTable = cn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
    string SheetName = schemaTable.Rows[0][2].ToString();
    StringBuilder SelectStatement = new StringBuilder();
    SelectStatement.Append("SELECT * FROM [").Append(SheetName).Append("]");
    System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter(SelectStatement.ToString(), cn);


    DataTable objDataTable = new DataTable();
    da.Fill(objDataTable);
  }



Try This code. Definatly it will work..
Thanks
Prince Sharma


[edit]Code block added, line format corrected[/edit]
 
Share this answer
 
v2
Comments
Richard MacCutchan 9-Jun-13 5:43am    
How will that work if the ACE library is not present on the macine?
nawabprince 11-Jun-13 13:09pm    
@bro you have to install driver as well as ms office on machine or ISS server.

I considered thats are already installed on machine..

Prince Sharma
Richard MacCutchan 11-Jun-13 13:13pm    
Read the question again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900