shieldguy
asked on
How to filter records in a dataset having 2 tables with Parent and Child Relationship
I have a dataset that contain 2 tables.
Table 1 = Child Table
Table 2 = Master Table
The dataset tables has got the Parent Child relationship using the following code:
ds.Relations.Add(ParentCol umn, ChildColumn);
What I want to achieve here is the filtered records using a criteria. For example the records of only the employees (Master Table) which are currently working in the company and not the leavers. To do that I need to use one of the columns in the master table but the records from the child table will be used to display on the form.
I hope I am clear explaining the problem.
Could anybody help please?
Table 1 = Child Table
Table 2 = Master Table
The dataset tables has got the Parent Child relationship using the following code:
ds.Relations.Add(ParentCol
What I want to achieve here is the filtered records using a criteria. For example the records of only the employees (Master Table) which are currently working in the company and not the leavers. To do that I need to use one of the columns in the master table but the records from the child table will be used to display on the form.
I hope I am clear explaining the problem.
Could anybody help please?
ASKER
Thanks for the code. I tried using this code but it doesn't recognize 'this.components'. I have no clue what is this components keyword. Anyways, Please have a look at the following code which I am trying to use and let me know the solution accordingly. Just to let you know that I am not using the native grid of dot net but the Infragistics ultra web grid which takes a table as it's datasource. There is no difference between binding a datasource to the native dot net grid and the ultra grid. Both take datatable as their datasource.
DataSet dsPers;
dsPers = oEmpPers.GetDataSetAsc(); //This returns the records of the child table
dsPers.Merge(dsEmpMstr.Tab les[0]); //This returns the records of the master table
dsPers.Relations.Add(dsPer s.Tables[1 ].Columns[ 0], dsPers.Tables[0].Columns[0 ]); //This creates the
//relation between
//the two tables of the dataset.
Finally I want to show the records from the child table of the dataset but by using a filter on a field called 'enable' which is present int he master table. i.e. 'enable = Y' which means to show only the employees which are enabled. The datasource of the grid is assigned by using the following line of code:
UGrid.DataSource = dsPers.Table[0]; //Table 0 is the child table.
DataSet dsPers;
dsPers = oEmpPers.GetDataSetAsc(); //This returns the records of the child table
dsPers.Merge(dsEmpMstr.Tab
dsPers.Relations.Add(dsPer
//relation between
//the two tables of the dataset.
Finally I want to show the records from the child table of the dataset but by using a filter on a field called 'enable' which is present int he master table. i.e. 'enable = Y' which means to show only the employees which are enabled. The datasource of the grid is assigned by using the following line of code:
UGrid.DataSource = dsPers.Table[0]; //Table 0 is the child table.
You Can ignore components - New BindingSource()
delete - this.components.Add(BsDeta
I use it for Dispose when form disposes.
Whe I add a BindingSource whith the Ide, Generate code includes Components.
private System.ComponentModel.IContainer components;
[DebuggerStepThrough]
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
....
[DebuggerNonUserCode]
protected override void Dispose(bool disposing)
{
try
{
if (((disposing && (this.components != null)) ? 1 : 0) != 0)
{
this.components.Dispose();
}
}
finally
{
base.Dispose(disposing);
}
}
ASKER
I am sorry but I dont' understand what you are trying to say here. Can you be a bit more clear please. I am not an expert in dot net but only a beginer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window