本文介绍了在单个查询中检索不同数据库的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我无法在单个查询中检索不同数据库的记录,而是使用以下代码:

Hi all,

I can''t retrieve records of the different databases in a single query, I use the following code:

OpenDatabase1()
OpenDatabase2()
Command.Connection = ConDB
Command.CommandType = CommandType.Text
Command.CommandText = "SELECT d1.Name,d2.Medium FROM Database1.Table1 AS d1, Database2.Table2 AS d2 WHERE d1.ID = d2.ID"
ObjDtReader = Command.ExecuteReader
  If ObjDtReader.Read = True Then
    Var1 = ObjDtReader("Name")
    Var2 = ObjDtReader("Medium")
End If
ObjDtReader.Close()
ConDB.Close()</pre>



如何获得这些记录?谢谢b4



how to get those records? thanks b4

推荐答案

SELECT d1.Name,d2.Medium 
FROM Database1.dbo.Table1 AS d1, 
     Database2.dbo.Table2 AS d2 
WHERE d1.ID = d2.ID


祝您编码愉快!
:)


Happy Coding!
:)



这篇关于在单个查询中检索不同数据库的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 21:44