我有 AdvanceDataGridView“customerTransactionDGV,資料源 =customersTransactionsBindingSource。
我正在使用以下 LINQ 代碼更改 CustomerComboBox 的 SelectionChangeCommitted 事件中的資料源。
this.customersTransactionsBindingSource.DataSource = dbContext.CustomersTransactions.Where(t => t.CustomerId.Equals(customerId)).ToList();
this.customersTransactionsTableAdapter.Fill(this.akDbDataSet.CustomersTransactions);
之后過濾器和資料網格視圖排序不起作用。
洗掉第一行代碼使其作業,但我需要這一行來填充 datagridview 與在 CustomerComboBox 中選擇的單個用戶的事務。
uj5u.com熱心網友回復:
這行代碼:
this.customersTransactionsTableAdapter.Fill(this.akDbDataSet.CustomersTransactions);
顯然從資料庫下載所有客戶交易。如果是真的,請不要這樣做
打開您的資料集,找到客戶交易表配接器,右鍵單擊它,選擇“添加查詢”,然后輸入:
SELECT * FROM CustomersTransactions WHERE CustomerId = @custId
將其稱為 FillByCustomerId(對于 getdataby 也是如此)
現在在您的代碼中,保留 bindingsource,停止更改其資料源(其資料源應設定為,并保持為this.akDbDataSet.CustomersTransactions),只需呼叫:
this.customersTransactionsTableAdapter.FillByCustomerId(this.akDbDataSet.CustomersTransactions, customerId);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/364666.html
上一篇:物體框架在運行時創建多個表C#
