Click here to Skip to main content
11,636,778 members (76,753 online)
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 1-Jan-13 23:28pm
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 jyo.net 263
1 stibee 249
2 Sergey Alexandrovich Kryukov 229
3 Suvendu Shekhar Giri 225
4 OriginalGriff 183
0 OriginalGriff 8,941
1 Sergey Alexandrovich Kryukov 8,493
2 Mika Wendelius 6,909
3 F-ES Sitecore 2,388
4 Suvendu Shekhar Giri 2,320


Advertise | Privacy | Mobile
Web04 | 2.8.150728.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