Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0 SQL-Server
How to join two table from two database using innerjoin in c#.
my Sql Query is
SELECT a.WorkAreaID, b.UserID , b.DisplayName FROM Test1.dbo.Resource a inner join Test2.dbo.User b ON
a.UserID =b.UserID
where Test1 and Test2 are database.
 

how to do this in c#?
Posted 2-Jan-13 0:28am
Comments
Aarti Meswania at 2-Jan-13 5:35am
   
you have already written query
it looks proper.
what is problem any error while execute?
SukirtiShetty at 2-Jan-13 5:49am
   
here is my c# code

DataTable dt = new Select(Test1.Resource.WorkAreaIDColumn, Test2.User.UserIDColumn, Test2.User.DisplayNameColumn).From(Test1.Resource.Schema).InnerJoin(Test2.User.Schema).ExecuteDataSet().Tables[0];
 
DataView dv = new DataView(dt);
 

I m getting this error: Invalid object name 'dbo.User'.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

try this if both databases are within same server:
SELECT a.userID, b.usersFirstName, b.usersLastName FROM databaseA.dbo.TableA a inner join database B.dbo.TableB b ON a.userID=b.userID
  Permalink  
Comments
SukirtiShetty at 2-Jan-13 22:56pm
   
this query is working in Sql server but i want query in c#

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

  Print Answers RSS
0 OriginalGriff 245
1 Jochen Arndt 155
2 PIEBALDconsult 150
3 Afzaal Ahmad Zeeshan 120
4 DamithSL 115
0 OriginalGriff 5,695
1 DamithSL 4,591
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 2 Jan 2013
Copyright © CodeProject, 1999-2014
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