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

时间:2019-08-28 05:32:46

标签: vb.net ms-access-2007 oledb oledbconnection oledbcommand

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

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)'

Connection1:

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

Connection2:

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)'

1 个答案:

答案 0 :(得分:0)

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