Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
VB
Try
            Dim Access As String = "|datadirectory|\datakaryawan.mdb"
            Dim Excel As String = "|datadirectory|\datakaryawanall.xls"
            Dim connect As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Excel & _
        ";Extended Properties=Excel 12.0;"
            Using cn As New OleDbConnection(connect)
                Using cmd As New OleDbCommand()
                    cmd.Connection = cn
                    cmd.CommandText = "INSERT INTO [MS Access;Database=" & Access & "].[datakaryawanall] SELECT * FROM [datakaryawanall$]"
                    cn.Open()
                    cmd.ExecuteNonQuery()
                End Using
            End Using
            Me.RefreshDataView()
            Me.bersih()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try


it show error message like this "external table is not in expected format"
Posted
Updated 21-Jun-15 20:06pm
v4
Comments
Michael_Davies 22-Jun-15 1:47am    
You Excel file is the Access database and vice versa.

This is what you have:

Dim Access As String = "|datadirectory|\datakaryawanall.xls"
Dim Excel As String = "|datadirectory|\datakaryawan.mdb"

This is what it should be:

Dim Access As String = "|datadirectory|\datakaryawan.mdb"
Dim Excel As String = "|datadirectory|\datakaryawanall.xls"
Akbar Giffary 22-Jun-15 2:05am    
yeah, i've improved it, but still getting error
Michael_Davies 22-Jun-15 3:14am    
Well beyond the names the rest does not look right, you connect to the Excel sheet using OLE, then try to INSERT into the Access database direct from the SQL, personally I have never seen an SQL command that took a connection string as a target but that might be a shortcoming of my experience.

Having said that you have asked this before and there is an example that was given and you only implemented part of that code:

https://social.msdn.microsoft.com/Forums/en-US/ba1f1926-3524-4375-8812-3ff300293b12/import-excel-sheet-to-access-database-using-vbnet

Also make sure that [datakaryawanall$] in the INSERT is the name of the sheet in the Excel file.
Akbar Giffary 22-Jun-15 3:29am    
yap of course, i sure that [datakaryawanall$] in the INSERT is the name of the sheet in the Excel file, so waht your opinion ? how i can import and replace data from excel to my access database ?, i'm stuck in here about 1 week -_-

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