Click here to Skip to main content
15,881,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai
In my windows application i have to export data from sql server to excel and import dataa from excel to sqlserver ,i done export data form sql server to excel,but again i need to import that data into sql server .i try the following code,but it show the error in connection of Datasouce
like "The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine."
VB
Private Sub radbtnImport_Click(sender As Object, e As EventArgs) Handles radbtnImport.Click
        Dim objConnection As New SqlConnection
        objConnection = New SqlConnection(My.Settings.CS)
        objConnection.Open()

        Dim MyConnection As System.Data.OleDb.OleDbConnection
        Dim DtSet As System.Data.DataSet
        Dim MyCommand As System.Data.OleDb.OleDbDataAdapter

        Dim fBrowse As New OpenFileDialog
        With fBrowse
            .Filter = "Excel files(*.xlsx)|*.xlsx|All files (*.*)|*.*"
            .FilterIndex = 1
            .Title = "Import data from Excel file"
        End With
        If fBrowse.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Dim fname As String
            fname = fBrowse.FileName
            MyConnection = New System.Data.OleDb.OleDbConnection("Provider= Microsoft.Jet.OLEDB.4.0; Data Source='" & fname & " '; " & "Extended Properties=Excel 8.0;")
            MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Personal]", MyConnection)
            MyCommand.TableMappings.Add("Table", "Test")
            DtSet = New System.Data.DataSet
            MyCommand.Fill(DtSet)'-- here i get error "The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine."
            MyConnection.Close()
            For Each Drr As DataRow In DtSet.Tables(0).Rows
           
 ''Here just i try to retive the data form excel one by one


                Dim Name As String = Drr(0).ToString
                Dim LastName As String = Drr(1).ToString
                Dim Contact As String = Drr(2).ToString
                Dim Phone As String = Drr(3).ToString
             
            Next
          
        End If


    End Sub



VB
MyConnection = New System.Data.OleDb.OleDbConnection("Provider= Microsoft.Jet.OLEDB.4.0; Data Source='" & fname & " '; " & "Extended Properties=Excel 8.0;")
here what i pass ? in Data Source ? full path with filename or path only ?

like

D:/Person.xlxs ? or D:/ or D:/Person ?


Regards
Aravind
Posted
Updated 15-Aug-13 1:10am
v4
Comments
Joezer BH 15-Aug-13 7:04am    
in the future try to paste the exact error message, it improves the ability to help you.
Aravindba 15-Aug-13 7:10am    
Thank for ur reply,i paste the exact error only "The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine."

1 solution

Seems like a common problem with interacting with Excel, Access of MS Office.
Have a look at those links:

- Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine[^]
- The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine” Error in importing process of xlsx to a sql server[^]
- OLEDB Provider is Not Registered on the Local Machine[^]


If you getting a "External table is not in the expected format" error perhaps you should change the connection from:
C#
MyConnection = New System.Data.OleDb.OleDbConnection("Provider= Microsoft.Jet.OLEDB.4.0; Data Source='" & fname & " '; " & "Extended Properties=Excel 8.0;")

to
C#
MyConnection = New System.Data.OleDb.OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0; Data Source='" & fname & " '; " & "Extended Properties=Excel 12.0;")




Good luck,
Edo
 
Share this answer
 
v2
Comments
Aravindba 15-Aug-13 8:04am    
Hi thank u for ur reply,after i change the Traget cpu to x86 it will move next line but i get error like "External table is not in the expected format."
bbirajdar 15-Aug-13 8:08am    
Use the import data tool in SSMS.. You can map the excel columns to the database table columns
Joezer BH 15-Aug-13 8:10am    
Updated the solution, see above suggestion to use Microsoft.ACE.OLEDB.12.0;
Aravindba 15-Aug-13 20:12pm    
Hi again thank u for ur reply and it work now,Thanks

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