Click here to Skip to main content
11,584,612 members (63,520 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 OriginalGriff 430
1 Sergey Alexandrovich Kryukov 367
2 Dave Kreskowiak 260
3 Richard Deeming 220
4 virusstorm 194
0 OriginalGriff 1,703
1 Sergey Alexandrovich Kryukov 1,267
2 Abhinav S 711
3 Dave Kreskowiak 687
4 Suvendu Shekhar Giri 568


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