Click here to Skip to main content
11,802,442 members (70,996 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#2.0 C# 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 1-Jan-13 23:28pm
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
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
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 KrunalRohit 366
1 OriginalGriff 365
2 F-ES Sitecore 295
3 Afzaal Ahmad Zeeshan 230
4 CPallini 230
0 OriginalGriff 2,950
1 Maciej Los 1,910
2 KrunalRohit 1,862
3 CPallini 1,645
4 Richard MacCutchan 1,157

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