[英]ADODB Connection to two access database
Due to ms access 2GB limitations on space;由于ms访问2GB的空间限制; i am considering splitting a database into two.我正在考虑将一个数据库一分为二。
However I regularly rely on SQL statements such as the following:但是,我经常依赖 SQL 语句,例如以下内容:
INSERT INTO [...] SELECT [...]
Is there a way in ADODB to perform the above, ie INSERT INTO table in file 1, the SELECT data from a table in file 2 ? ADODB 中有没有办法执行上述操作,即文件 1 中的 INSERT INTO 表,文件 2 中表中的 SELECT 数据?
Here's an example of updating one accdb from another using VBA and ADO:这是使用 VBA 和 ADO 从另一个更新一个 accdb 的示例:
Sub AddDataFromAccessToAccess()
Dim cn As Object
Dim sDatabase As String
Dim sDatabase2 As String
' change these paths
sDatabase = "C:\Database1.accdb"
sDatabase2 = "C:\Database2.accdb"
Set cn = CreateObject("ADODB.Connection")
With cn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.ConnectionString = "Data Source='" & sDatabase & "'"
.Open
' change table and field names here
.Execute "INSERT INTO Table1 ([Field1]) SELECT [Field2] FROM [MS Access;DATABASE=" & sDatabase2 & ";].[Table2]"
.Close
End With
End Sub
Instead of setting your db to CurrentDB, use OpenDatabase.不要将数据库设置为 CurrentDB,而是使用 OpenDatabase。
eg.
set DB = opendatabase("fkdslfjslj")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.