Steps to do:
1) create OleDbConnection and open it
2) create OleDbCommand, DataTable and fetch MS Access database data into datatable, providing column names mapping in SQL query
SELECT col1, col2, name as nameperson, family as family1, col5, col6,... colN
FROM ...
3) create SqlConnection and open it
4) copy data using bulkcopy
WARNING:
The structure and datatypes for both tables must be the same!
Example function:
Function CopyData(ByVal sSQL As String, ByVal sDbName As String, ByVal sDestTableName As String) As Integer
Dim retVal As Integer = 0, sAccConn As String = String.Empty
Dim oAccConn As OleDb.OleDbConnection = Nothing, oAccComm As OleDb.OleDbCommand = Nothing, oAccRdr As OleDb.OleDbDataReader = Nothing
Dim oSqlConn As SqlClient.SqlConnection = Nothing, oSqlBC As SqlClient.SqlBulkCopy = Nothing, oSqlComm As SqlClient.SqlCommand = Nothing, oSqlRdr As SqlClient.SqlDataReader = Nothing
Dim oDt As Data.DataTable = Nothing
Try
sAccConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sDbName & ";Jet OLEDB:Database Password=myPass;"
oAccConn = New OleDb.OleDbConnection(sAccConn)
oAccConn.Open()
oAccComm = New OleDb.OleDbCommand(sSQL, oAccConn)
oAccRdr = oAccComm.ExecuteReader()
oSqlConn = New SqlClient.SqlConnection(sSQLConnString)
oSqlConn.Open()
oSqlBC = New SqlClient.SqlBulkCopy(oSqlConn)
With oSqlBC
.DestinationTableName = sDestTableName
.WriteToServer(oAccRdr)
End With
oSqlComm = New SqlClient.SqlCommand("SELECT * FROM " & sDestTableName, oSqlConn)
oSqlRdr = oSqlComm.ExecuteReader()
oDt = New Data.DataTable(sDestTableName)
oDt.Load(oSqlRdr)
retVal = oDt.Rows.Count
oDt.Dispose()
Catch ex As OleDb.OleDbException
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "OleDb Error")
Catch ex As SqlClient.SqlException
MsgBox(ex.Message & vbCr & "Tabela: " & sDestTableName, MsgBoxStyle.Exclamation, "SQL Error")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error")
Finally
oDt.Dispose()
oDt = Nothing
oAccRdr = Nothing
oAccComm.Dispose()
oAccComm = Nothing
If oAccConn.State = ConnectionState.Open Then oAccConn.Close()
oAccConn.Dispose()
oAccConn = Nothing
oSqlComm.Dispose()
oSqlComm = Nothing
oSqlRdr = Nothing
oSqlBC = Nothing
If oSqlConn.State = ConnectionState.Open Then oSqlConn.Close()
oSqlConn = Nothing
End Try
Return retVal
End Function