2013-01-21 31 views
0

我有兩個表有master-child關係,有幾百萬條記錄。我正在使用Visual Studio生成的類型化數據集。由於我的表非常大,而且我不想實現虛擬模式,因此我使用SELECT TOP X修改了主表,以限制查看的行數,並按內部條件排序。現在,子表的問題是它仍然在應用程序啓動時帶來了數百行。DataGridview主/明細大表

什麼是仍然使用生成的DataSet並限制子DataGridView加載所有數據的解決方案?我想到的第一個解決方案是在master DataGridView中更改了行選擇的事件中手動實施SqlDataAdapter數據填充子行。這似乎只是按需加載。

回答

0

由於沒有響應,到目前爲止,這裏是最快的解決方案,我能找到的:

  1. 保持當前的類型化數據集和表適配器添加
  2. 使用的數據集FillBY方法添加到您的孩子的TableAdapter設計師。例如here
  3. 從Form_Load事件調用子刪除的TableAdapter填寫()方法,該方法是將您的所有數據庫結果有
  4. 對於主表CurrentChanged事件的產生的BindingSource的創建一個處理程序,並在其添加表單加載事件。 應該是這樣的:

    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"]); 
         } 
    
    }