Click here to Skip to main content
13,558,486 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
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 2-Jan-13 5:35am
   
you have already written query
it looks proper.
what is problem any error while execute?
SukirtiShetty 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 2-Jan-13 22:56pm
   
this query is working in Sql server but i want query in c#
zachkay 23-Feb-18 2:24am
   
sir, how if the database in different server?

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 |
Web04-2016 | 2.8.180515.1 | Last Updated 2 Jan 2013
Copyright © CodeProject, 1999-2018
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