Click here to Skip to main content
15,916,692 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to export excel file into sql database table...When i try to run that i had the folowing error at runtime.........."The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.".....................Anyone please help me that?

Aspx File :

XML
<table>
    <tr>
        <td>
            <span style="color: Red">*</span>Attach Excel file
        </td>
    <td>
        <asp:FileUpload ID="fileuploadExcel" runat="server" />
    </td>
    </tr>
    <tr>
        <td></td>
        <td>
            <asp:Button ID="btnSend" runat="server" Text="Export" onclick="btnSend_Click"  />
        </td>
    </tr>
</table>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>


Aspx.cs File :

C#
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSend_Click(object sender, EventArgs e)
    {
        String strConnection = "Data Source=(local);Initial Catalog=MyDB;Integrated Security=True";
        //file upload path
        string path = fileuploadExcel.PostedFile.FileName;
        //Create connection string to Excel work book
        string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;Persist Security Info=False";
        //Create Connection to Excel work book
        OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
        //Create OleDbCommand to fetch data from Excel
        OleDbCommand cmd = new OleDbCommand("Select [ID],[Name],[Designation] from [Sheet1$]", excelConnection);
        excelConnection.Open();
        OleDbDataReader dReader;
        dReader = cmd.ExecuteReader();
        SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection);
        //Give your Destination table name
        sqlBulk.DestinationTableName = "Excel2TB";
        sqlBulk.WriteToServer(dReader);
        excelConnection.Close();
    }
Posted
Updated 2-Apr-13 19:39pm
v3
Comments
Karthik Harve 3-Apr-13 1:40am    
[Edit] pre tags added.

Hi,
You need to install Microsoft excel 2007, it will automatically install the 'Microsoft.ACE.OLEDB.12.0' driver in your system. I also get the same problem, after installing the MS Excel, it will works fine. I hope this will help you.


With regards,
J.Prabu
[Email:prbspark@gmail.com]
 
Share this answer
 
Comments
SnvMohan 3-Apr-13 3:00am    
Thank you
That means you don't have Microsoft.ACE.OLEDB.12.0. Download it and install from here[^].

And also check
HOW TO: FIX ERROR - "the 'microsoft.ace.oledb.12.0' provider is not registered on the local machine".0' provider is not registered on the local machine"[^]

--Amit
 
Share this answer
 
Comments
Maciej Los 3-Apr-13 1:47am    
+5!
_Amy 3-Apr-13 1:50am    
Thank you Maciej. :)
SnvMohan 3-Apr-13 3:01am    
Thank you so much
_Amy 3-Apr-13 3:07am    
Welcome. :)

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