7
Answers

Join query for two tables from two databases C# Win App

Mayank Jani

Mayank Jani

7y
276
1
Dear All,
 
Greetings of the day...
 
I am learning C# with Windows application and in a form I want to get a crystal report of employee details. there are two databases and the data will be fetched from two tables i.e. T1 table from DB1 database and T2 table from DB2 database. I am applying inner join to fetch record.
 
DB1=Employees, T1=EmpDetails.
DB2=Masters,      T2=City.
 
I am trying to fetch EmpName, EmpDesig, EmpDoj from DB1 and EmpCity from DB2.
 
Please see the code...
 
private void btnShow_Click(object sender, EventArgs e)
{
//OleDbDataAdapter ShowEmp = new OleDbDataAdapter("Select Experiments.Employee.EmpName,Experiments.Employee.EmpDoJ,Experiments.Employee.EmpDesignation,ExperimentsMAS.MasterCity.CityName From Experiments.Employee Inner Join ExperimentsMas.MasterCity On Experiments.Employee.EmpCity=ExperimentsMAS.MasterCity.CityID Where Experiments.Employee.EmpName=" + cmbEmployee.Text, MyConn);

//OleDbDataAdapter ShowEmp = new OleDbDataAdapter("Select EmpName, EmpDoj, EmpDesignation From Experiments.Employee as T1 Inner Join MasterCity ExperimentsMAS.MasterCity as T2 on T1.EmpCity=T2.ID", MyConn);

//OleDbDataAdapter ShowEmp = new OleDbDataAdapter("Select a.*,b.* From Experiments.dbo.Employee as a left join ExperimentsMAS.dob.MasterCity as b on a.EmpCity=b.ID", MyConn);

DataSet dsShowEmp = new DataSet();
ShowEmp.Fill(dsShowEmp);

CR_MultiDB XYZ = new CR_MultiDB();
XYZ.SetDataSource(dsShowEmp.Tables[0]);
CRVEmployee.ReportSource = XYZ;
 
Three queries from different sources of net (google, of course) but none of them works. 
I run inner join from same DB but I want to join two tables from two database.
 
Please note that... 1. I use MS Access as database. 2. It's Windows application, and 3. please show me other simple mathod to do this, if any.
 
Thank you.
 
Mayank Jani.
Answers (7)