我有两个master-child
关系表,有几百万条记录。我正在使用visual studio生成的类型化数据集。由于我的表非常大并且我不想实现虚拟模式,因此我使用SELECT TOP X
修改了主表,以限制所看到的行数,按内部条件排序。现在,子表的问题在于它仍然在应用程序启动时带来了数百万行。
仍在使用生成的DataSet
并限制子DataGridView
加载所有数据的解决方案是什么?我想到的第一个解决方案是在主事件SqlDataAdapter
中更改行选择的事件中手动实现子行的DataGridView
数据填充。这似乎只是按需加载。
答案 0 :(得分:0)
由于到目前为止没有回复,这是我能找到的最快的解决方案:
为主表生成的bindingSource的CurrentChanged事件创建一个处理程序,并以表单Load事件的形式添加它。 应该是这样的:
this.myMasterTableBindingSource.CurrentChanged + = new EventHandler(myMasterTableBindingSource_CurrentChanged);
使用基于主表中所选项目的信息填充您的子dataGridView:
void myMasterTableBindingSource_CurrentChanged(object sender, EventArgs e)
{
DataRowView selectedRow = myMasterTableBindingSource.Current as DataRowView;
if (selectedRow != null && !selectedRow.IsNew)
{
this.myChildTableTableAdapter.FillByUser(this.myDataSet.MyChildTable, (int)selectedRow["UserID"]);
}
}