Click here to Skip to main content
12,242,431 members (55,035 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: SQL-server-2005 VB SQL-Server , +
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>

how to get those records? thanks b4
Posted 13-Sep-12 21:50pm
om3n580
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

you forgot to write schema name 'dbo'
SELECT d1.Name,d2.Medium 
FROM Database1.dbo.Table1 AS d1, 
     Database2.dbo.Table2 AS d2 
WHERE d1.ID = d2.ID
Happy Coding!
Smile | :)
  Permalink  
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!
:)
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Use a stored Proc and call stored proc from c#.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 14 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100