Click here to Skip to main content
12,755,652 members (39,159 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:

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

how to get those records? thanks b4
Posted 13-Sep-12 21:50pm
Rate this: bad
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!
om3n 14-Sep-12 3:36am
thank you for quick reply, the problem can be solved :)
aarti meswania 14-Sep-12 3:37am
Glad to help you!
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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

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.170217.1 | Last Updated 14 Sep 2012
Copyright © CodeProject, 1999-2017
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