Irwsoft Data Framework

Inner Join
Brief Information
EditionsAll Editions
TopicsSelect relation table using join syntax.
RemarksThis documentation also apply to cross join, inner join, left join and right join.

This sample will show you how to select relation tables using join syntax.

Example : We want to display all records of Person table that have leader.

      SELECT P1.*, P2.PersonID, P2.FirstName FROM PERSON P1 INNER JOIN PERSON P2 ON P1.LeaderID = P2.PersonID

C# code
// Declare and initiate a new instance PersonTable that represent as member data
PersonTable member = new PersonTable();

// Declare and initiate a new instance PersonTable that represent as leader data
PersonTable leader = new PersonTable();

SqlSelectFrom select = new SqlSelectFrom(member);
// Don’t forget to set connection string !
// NOTE : it is optional if the data-schema class using default connection.

select.ConnectionString = "...";  // [OPTIONAL]

// select specific columns of member to display or just select all columns.
// select.Columns.Add(member.FirstName);
// select.Columns.Add(member.LeaderId);


// to display member/s with his/her leader data,
// we will use INNER-JOIN between member.LeaderId and leader.PersonId

select.Tables.InnerJoin(leader).On.Compare(member.LeaderId, ComparisonOperator.Equal, leader.PersonId);

// Note : if not specified then no columns of leader will be displayed
//        you can select columns of leader to display after set the join


// Execute the query
Irwsoft.Data.DataView dv = select.Execute();

// here how to access data from DataView by define which column to read the data
String firstNamePerson = dv.Rows[0][member.FirstName].ToString();
String firstNameLeader = dv.Rows[0][leader.FirstName].ToString();

Related Topics :

Irwsoft Data Ultimate Edition provides comprehensive features of Irwsoft Data Framework and support from irwsoft.