Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Insert data from sql database to access file using vb.net

I need to export data from SQL database table to MS Access table, tables are there in both. I tried using 'Insert into' query :

Private Sub Export(ByVal destinationpath As String)
    Dim AccessConn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + destinationpath)
    AccessConn.Open()

    Dim AccessCommand As New System.Data.OleDb.OleDbCommand("INSERT INTO [Contact] Select * From [Contact] IN '' [ODBC;Driver={SQL Server};Server=localhost\sqlexpress;Database=Database1;Trusted_Connection=yes];", AccessConn)

    AccessCommand.ExecuteNonQuery()
    AccessConn.Close()
End sub

This code is working, but I want to get data from contact table using 'Where' condition. So I added it like this:

Dim AccessCommand As New System.Data.OleDb.OleDbCommand("INSERT INTO [Contact] Select * From [Contact] where [Contact].[Contactid] In (1) IN '' [ODBC;Driver={SQL Server};Server=localhost\sqlexpress;Database=Database1;Trusted_Connection=yes];", AccessConn)

It's throwing a syntax error.

Comments