如何从具有不同连接的另一个数据库表中更新JOIN数据?

问题描述 投票:0回答:1

我下面的代码可以与数据库中的另一个表更新和内部联接数据,它也只使用一个连接字符串,因为它们都在同一数据库中。

Dim connstring1 As String
connstring1 = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=AMP.accdb"

Dim conn1 As OleDbConnection = New OleDbConnection(connstring1)
Dim updatescardrate As String = "UPDATE scard INNER JOIN Employee_Records ON scard.controlnumber = Employee_Records.controlnumber SET scard.rate = Employee_Records.rate"
Dim cmdupdatescardrate As New OleDbCommand(updatescardrate, conn1)

conn1.Open()
cmdupdatescardrate.ExecuteNonQuery()
conn1.Close()

示例预期结果插图:

UPDATE Table scard.column1 '(this is from connection1, database: AMP.accdb)'
and JOIN data from Table criteria.column3 '(this is from connection2, database: IMS.accdb)'

连接1:

Dim connstring1 As String
connstring1 = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=AMP.accdb"

连接2:

Dim connstring2 As String
connstring2 = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=IMS.accdb"

示例预期结果插图:

UPDATE Table scard.column1 '(this is from connection1, database: AMP.accdb)'
and JOIN data from Table criteria.column3 '(this is from connection2, database: IMS.accdb)'
vb.net ms-access-2007 oledb oledbconnection oledbcommand
1个回答
0
投票

最简单的方法是在第一个数据库中创建到第二个数据库的链接表。比起两个表,您可以同时使用它们。

© www.soinside.com 2019 - 2024. All rights reserved.