I have two Sql Server databases d1 and d2 which are in the same physical server. d1 has a table address, d2 has a table telephone. I want to join them in a C# project, I googled and tried many ways, but all failed. If anybody can provide a simple but "COMPLETE and RUNNABLE" C# example project, that would be greatly appreciated.
[d1].[dbo].[address]:
id name address
1 Adam add1
2 Bob add2
3 Pete add3
4 Hans add4
[d2].[dbo].[telephone]:
id addr_id phoneNumber
1 2 632532
2 1 233257
3 4 343439
4 3 798111
addr_id is a foreign key with the reference to id of table address in database d1.
ConnectionString_d1 = "Data Source=ServerName;" + "Initial Catalog=d1;" + "User id=ui;" + "Password=pd;";
ConnectionString_d2 = "Data Source=ServerName;" + "Initial Catalog=d2;" + "User id=ui;" + "Password=pd;";
Certainly, you need change the two connection strings according to your own databases for the test.
SELECT t1.name, t1.address, t2.phoneNumber
FROM [d1].[dbo].[address] t1
INNER JOIN [d2].[dbo].[address] t2
ON t1.id = t2.addr_id;
Please don't just tell me the T-Sql statement mentioned above that only works in MSSQL Management Studio, doesn't work in a C# project. I need the simple but the COMPLETE Implementation of a C# console application that can be built and run, thanks in advance!