There is a simple demo for DataRelation class of DataSet.
while u can use DataTable.Select(conditions) or DataView.Filter to filete the data what you want .however,maybe the method is more complex with this one.
datatalbeperformancetest #region datatalbeperformancetest /**/ /// <summary> /// Testtablerelation. /// </summary> public void Relation() ... { DataTabledtParent = this .CreateDataTable(); dtParent.TableName = " Parent " ; .netframework2.0 #region .netframework2.0 DataSetds= new DataSet(); ds.Tables.Add(dtParent); DataRelationrelations = ds.Relations.Add( " Relation " ,ds.Tables[ " Parent " ].Columns[ " index " ],ds.Tables[ " Parent " ].Columns[ " parent_index " ], false ); foreach (DataRowrow in ds.Tables[ " Parent " ].Rows) #endregion .netframework1.1 #region .netframework1.1 // DataRelationrelations=newDataRelation("Relation",dtParent.Columns["index"],dtParent.Columns["parent_index"],false); // foreach(DataRowrowindtParent.Rows) #endregion ... { if ( 0 != string .Compare(row[ " parent_index " ].ToString(), " 0 " , true ,System.Globalization.CultureInfo.CurrentCulture)) ... { continue ; } this .DebugPrint( string .Format( " {0} " ,row[ " description " ].ToString())); this .PrintChilds(row,relations); this .DebugPrint( " -------------------------------------------------- " ); } }/**/ /// <summary> /// printthechild /// </summary> private void PrintChilds(DataRowrowParent,DataRelationrelations) ... { DataRow[]rowChilds = rowParent.GetChildRows(relations); if ( null == rowChilds || 0 == rowChilds.Length) ... { return ; } string spaces = string .Empty; foreach (DataRowrow in rowChilds) ... { spaces = spaces.PadLeft( int .Parse(row[ " layer " ].ToString()), ' ' ); this .DebugPrint( string .Format( " {0}|--{1} " ,spaces,row[ " description " ].ToString())); this .PrintChilds(row,relations); } }/**/ /// <summary> /// Createthedatatablefortest. /// </summary> /// <returns></returns> private DataTableCreateDataTable() ... { DataTabledt = new DataTable( " Test " ); // addcolumns dt.Columns.Add( new DataColumn( " index " , typeof (Int32))); dt.Columns.Add( new DataColumn( " parent_index " , typeof (Int32))); dt.Columns.Add( new DataColumn( " description " , typeof ( string ))); dt.Columns.Add( new DataColumn( " layer " , typeof ( string ))); // addrows dt.Rows.Add( new object [] ... { 1000 , 0 , " first1 " , 0 } ); dt.Rows.Add( new object [] ... { 1001 , 1000 , " secord2 " , 1 } ); dt.Rows.Add( new object [] ... { 2000 , 0 , " third3 " , 0 } ); dt.Rows.Add( new object [] ... { 2001 , 1000 , " forth4 " , 2 } ); dt.Rows.Add( new object [] ... { 3000 , 2000 , " fifth5 " , 1 } ); dt.Rows.Add( new object [] ... { 3001 , 3000 , " six6 " , 2 } ); dt.Rows.Add( new object [] ... { 2222 , 0 , " seven7 " , 0 } ); dt.Rows.Add( new object [] ... { 100 , 2222 , " first11 " , 1 } ); dt.Rows.Add( new object [] ... { 101 , 1000 , " secord21 " , 1 } ); dt.Rows.Add( new object [] ... { 200 , 222 , " third31 " , 3 } ); dt.Rows.Add( new object [] ... { 201 , 1001 , " forth41 " , 2 } ); dt.Rows.Add( new object [] ... { 300 , 2000 , " fifth51 " , 1 } ); dt.Rows.Add( new object [] ... { 301 , 3000 , " six61 " , 2 } ); dt.Rows.Add( new object [] ... { 222 , 1000 , " seven71 " , 3 } ); // acceptchanges dt.AcceptChanges(); // DataSetds=newDataSet("Test"); // ds.Tables.Add(dt); return dt; } private void DebugPrint( string msg) ... { // System.Diagnostics.Debug.WriteLine(msg); Console.WriteLine(msg); } #endregion