0

我有两个master-child具有几百万条记录的关系表。我正在使用由 Visual Studio 生成的类型化数据集。由于我的表非常大并且我不想实现虚拟模式,因此我使用 , 修改了主表SELECT TOP X,以限制看到的行数,按内部标准排序。现在子表的问题是它仍然会在应用程序启动时带来数百万行。

仍然使用生成DataSet并限制子DataGridView加载所有数据的解决方案是什么?我想到的第一个解决方案是SqlDataAdapter在 master 中更改行选择的事件中手动实现子行的数据填充DataGridView。这似乎只按需加载。

4

1 回答 1

0

由于到目前为止没有回应,这是我能找到的最快的解决方案:

  1. 保持添加当前类型化的数据集和表适配器
  2. 使用数据集设计器将 FillBY 方法添加到您的子 tableAdapter。这里的例子
  3. 从 Form_Load 事件中删除对子 tableAdapter Fill() 方法的调用,该方法将所有数据库结果带到那里
  4. 为您为主表生成的 bindingSource 的CurrentChanged事件创建一个处理程序,并将其添加到表单 Load 事件中。应该是这样的:

    this.myMasterTableBindingSource.CurrentChanged += new EventHandler(myMasterTableBindingSource_CurrentChanged);

  5. 使用基于主表中所选项目的信息填充您的子 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"]);
            }
    
    }
    
于 2013-01-31T10:03:06.503 回答