从组合表中读取主表和子表

本文关键字:组合 读取 | 更新日期: 2023-09-27 18:00:53

Am使用Infrastics UltraWinGrid.UltraGrid控件在我的.Net 3.5 winforms应用程序中显示分层数据。从我的中间层,我得到了一个数据表,它合并了主表和子表的数据。我可以使用groupby子句获取子表的数据。

使用DataRelation如下,然后将包含主表和子表的本地数据集变量绑定到网格。

ds.Tables.Add(tableMaster); 
ds.Tables.Add(tableChild);
DataRelation reln = new DataRelation("MyReln", ds.Tables[0].Columns[colName], ds.Tables[1].Columns[colName], false);
ds.Relations.Add(reln); 
ds.AcceptChanges(); 
this.ultraGrid.DataSource = ds;

我的问题是,从上面的合并数据表中读取这个tableMaster和tableChild的最快方法是什么?

谢谢。

从组合表中读取主表和子表

也许您应该在DataGridView控件中存储一个JOIN结果:

string sql = "SELECT * " +
  "FROM TableMaster M " +
  "LEFT JOIN TableChild C ON M.ColName=C.ColName";
// SelectDataTable would be your collection method
DataTable bigTable = SelectDataTable(sql);
this.ultraGrid.DataSource = bigTable.DefaultView;

这样,您的数据将始终可用。

编辑:当然,您可以随时将bigTable添加到DataSet中,并在必要时访问它。