高分求! ADO.NET之DataView 如何高效过滤!!!
有如下表:
表1:Dealer
field:
Dealer_ID char(10) PK
...
数据量:2行
表2:Dealer_category
field:
Dc_ID char(10) PK
dealer_ID char(10)
...
数据量:274行
表3:Dealer_product
field:
Dp_ID char(10) PK
Product_name nvarchar(50)
...
数据量:5462行
表4:Product_category
field:
Pc_ID char(10) PK
Dp_ID char(10)
Dc_ID char(10)
...
数据量:9109行
表5:Product_ready
field:
Pr_ID char(10) PK
Dp_ID char(10)
...
数据量:467行
在WinForm里操作,上述5表均完全读入DataTable缓存
Dp_list为DataGridview
需要在Dp_list内显示Dealer_product内容
Treeview1用树显示Dealer_category,点击treenode时,用dpsource对Dp_list进行过滤(条件:当前treenode及childnode中包含的Dc_ID所对应的Dp_ID,以及不在Product_ready中的DpID)
ado.net新人,目前只会简单操作,用下列代码,4秒以上才过滤完成。
求高效的方法!拜谢!
Private dpsource As New DataView(mydataset.Tables("Dealer_product")) 'DPlist数据源 Private dcstr As String '当前选择的dcIDs '过滤dplist Private Sub TreeView1_NodeMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseClick getnodevalue() dplist_show(getdp(dcstr)) End Sub '取当前选择node的值 Private Sub getnodevalue() dcstr = Chr(39) & currnode.Name.ToString & Chr(39) If currnode.GetNodeCount(False) > 0 Then For Each tmpnode As TreeNode In currnode.Nodes dcstr &= " , '" & tmpnode.Name.ToString & Chr(39) Next End If 'MsgBox("currnode value:" & dcstr) End Sub '取得当前dc的DPs Private Function getdp(Optional ByVal _Dc_ID As String = Nothing) As String If _Dc_ID = Nothing Then Return " " Else Dim dpstr As New StringBuilder For Each tmpdp As DataRow In mydataset.Tables("Product_category").Select("Dc_ID in (" & _Dc_ID & ")") Dim findrow As DataRow() = mydataset.Tables("Product_ready").Select("Dp_ID = '" & tmpdp("Dp_ID").ToString & "'") If findrow.Length = 0 Then dpstr.Append("'" & tmpdp("Dp_ID").ToString & "',") End If Next If dpstr.Length > 0 Then dpstr.Remove(dpstr.Length - 1, 1) Return dpstr.ToString Else Return Nothing End If End If End Function '过滤Dplist Private Sub dplist_show(Optional ByVal _Dp_ID As String = Nothing) If _Dp_ID = Nothing Then dpsource.RowFilter = "Dp_ID = '1 '" Else dpsource.RowFilter = "Dp_ID in (" & _Dp_ID & ") and use_status = '使用中'" End If End Sub