问题
For some time we've been retrieving data from a remote MS Access database and copy its contents to a local Access DB with a simple SELECT * INTO query. However we're currently in a migration process which requires to retrieve data from the MySQL database and copy it to the local Access DB, thus the aforementioned query won't work here for obvious reasons.
Now seeing as I can't use any external programs and are only allowed to write in VB.NET, my method to transfer the data over is by using datatables. It does its job, but the performance is dreadful.
My questions therefore is, is there a fast way to transfer/copy data from the remote MySQL database to a local MS Access with only using VB.NET.
My current code: pastebin.com/ELmkVFSc
回答1:
Very roughly:
Imports Microsoft.Office.Interop.Access.Dao
Module Module1
Sub Main()
Dim dbEng As New DBEngine()
Dim ws As Workspace
Dim db As Database
ws = dbEng.CreateWorkspace("", "admin", "", WorkspaceTypeEnum.dbUseJet)
db = ws.OpenDatabase("z:\\docs\\test.accdb", False, False, "")
db.Execute("SELECT * INTO Newtable From [ODBC;DSN=MySQL;].test")
End Sub
End Module
You could also have a query on these lines:
SELECT * INTO Newtable FROM
[ODBC;Driver={MySQL ODBC 5.1 Driver};Server=127.0.0.1;Database=test;User=usr;Password=pwd;CLIENT_MULTI_RESULTS;Option=3;].test;
来源:https://stackoverflow.com/questions/12591809/mysql-to-ms-access