I'm starting to try to fully take advantage of the very powerful "DataSet" structure in .net. I've learned a few things in the last few days, like how to get child rows based on a relationship. The call:
DataTable.GetChildRows(...
) returns an array of DataRow. The question is, what's the easiest way to get these data rows back into a format that can be used as the datasource for a databound control (like a datagrid)? My current solution (which feels like a hack) is:
DataTable dt = DataSet1.Tables[0];
DataRow[] rows = dt.GetChildRows(...);
DataTable dt2 = dt.Clone();
foreach (DataRow row in rows) dt2.Rows.Add(row);
DataGrid1.DataSource = dt2;
// What I really want to be able to do, is something more like this:
DataTable dt = DataSet1.Tables[0];
DataGrid1.DataSource = (DataTable) dt.GetChildRows(...);
// or
DataGrid1.DataSource = new DataTable(dt.GetChildRows(
...));
// or
DataGrid1.DataSource = ???
Any guidence is greatly appreciated. Take care.
Start Free Trial