Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,

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

VB
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>


how to get those records? thanks b4
Posted

you forgot to write schema name 'dbo'
SQL
SELECT d1.Name,d2.Medium 
FROM Database1.dbo.Table1 AS d1, 
     Database2.dbo.Table2 AS d2 
WHERE d1.ID = d2.ID

Happy Coding!
:)
 
Share this answer
 
Comments
om3n 14-Sep-12 3:36am    
thank you for quick reply, the problem can be solved :)
Aarti Meswania 14-Sep-12 3:37am    
welcome,
Glad to help you!
:)
Use a stored Proc and call stored proc from c#.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900