use this solution i.e. use linq to query on datatable
public DataSet ds;
public DataTable dt, dt1;
ds = new DataSet();
dt = new DataTable();
dt.TableName = "Employee";
dt.Columns.Add("EmployeeID", typeof(Int32));
dt.Columns.Add("Name");
ds.Tables.Add(dt);
dt1 = new DataTable();
dt1.TableName = "EmployeeAddress";
dt1.Columns.Add("EmployeeID", typeof(Int32));
dt1.Columns.Add("EmployeeAddressID", typeof(Int32));
dt1.Columns.Add("Address");
dt1.Columns.Add("AddressType");
ds.Tables.Add(dt);
ds.Tables.Add(dt1);
var result = from emp in ds.Tables[0].AsEnumerable()
join empAdd in ds.Tables[1].AsEnumerable()
on (int)emp["EmployeeID"] equals (int)empAdd["EmployeeID"]
select new
{
EmployeeID = (int)emp["EmployeeID"],
Name = (string)emp["Name"],
Address = (string)empAdd["Address"],
AddressType = (string)empAdd["AddressType"]
};
foreach (var emp in result)
{
Console.WriteLine(String.Format("EmployeeID : {0} , Name : {1} , Address : {2} , AddressType : {3}", emp.EmployeeID,emp.Name,emp.Address,emp.AddressType));
}
var result = from emp in ds.Tables[0].AsEnumerable()
join empAdd in ds.Tables[1].AsEnumerable()
on (int)emp["EmployeeID"] equals (int)empAdd["EmployeeID"] into AddGrp
from record in AddGrp.DefaultIfEmpty()
select new
{
EmployeeID = (int)emp["EmployeeID"],
Name = (string)emp["Name"],
Address = record == null ? string.Empty : (string)record["Address"],
AddressType = record == null ? string.Empty : (string)record["AddressType"]
};
foreach (var emp in result)
{
Console.WriteLine(String.Format("EmployeeID : {0} , Name : {1} , Address : {2} , AddressType : {3}", emp.EmployeeID, emp.Name, emp.Address, emp.AddressType));
}