{Import Failed, correct Column name in the sheet!, Error Message: The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine}
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' delete the file with the same and create a new access file If File.Exists("C:\Users\Admin\Desktop\test\CA\book.mdb") Then File.Delete("C:\Users\Admin\Desktop\test\CA\book.mdb") End If Dim _accessData As Access.Application _accessData = New Access.Application() _accessData.Visible = False _accessData.NewCurrentDatabase("C:\Users\Admin\Desktop\test\CA\book.mdb", Access.AcNewDatabaseFormat.acNewDatabaseFormatAccess2000, , , ) _accessData.CloseCurrentDatabase() _accessData.Quit(Microsoft.Office.Interop.Access.AcQuitOption.acQuitSaveAll) _accessData = Nothing ' initialize the connect string Dim _filename As String = "C:\Users\Admin\Desktop\test\CA\test.xls" Dim _conn As String _conn = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\Users\Admin\Desktop\test\CA\test.xls" & _filename & ";" & "Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";" Dim _connection As OleDbConnection = New OleDbConnection(_conn) 'Use OledbCommand object to select all the data from sheet1 and execute an ExecuteNonQuery to import data into Book.mdb. Dim _command As OleDbCommand = New OleDbCommand() _command.Connection = _connection Try _command.CommandText = "SELECT * INTO [MS Access;Database=C:\Users\Admin\Desktop\test\CA\book.mdb].[Sheet1] FROM [Sheet1$A4:D]" _connection.Open() _command.ExecuteNonQuery() _connection.Close() MessageBox.Show("The import is complete!") Catch e1 As Exception MessageBox.Show("Import Failed, correct Column name in the sheet!" & Environment.NewLine & "Error Message:" & Environment.NewLine & e1.Message) End Try End Sub,
SELECT * INTO [MS Access;Database=C:\Users\Admin\Desktop\test\CA\book.mdb].[Sheet1] FROM [Sheet1$A4:D <missed final row> ]"
SELECT <Field_names> INTO ... FROM ...
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)