以下是引用Bin在2014-4-11 8:58:00的发言:
应该是 SQL 加载条件语句不允许这么长. 你还是采取分页加载吧. 效率又高,何乐而不为
分页加载如何写呢?因为我是两个表的加载,先加载的为子表,后加载的为父表,就是说父表是用户看不见的,用户只是看到子表,而了表的一些字段是用表达式的,表达式是引用父表的数据,所以当用户需要查子表时,他会根据我给的加载树,选择加载子表的数据,当加载完子表数据时,再去由程序根据条件加载父表的数据。
这是加载树窗口
AfterLoad代码:
Dim cmd As New SQLCommand
cmd.C
Dim dt As DataTable
cmd.CommandText = "Select Distinct {obas_part1}.[part_type],[part_name],[type_name] From ({obas_part1} Inner JOIN {obas_part} ON {obas_part}.[part_no] = {obas_part1}. [part_no]) Inner JOIN {obas_part_type} ON {obas_part_type}.[type_no] = {obas_part1}.[part_type] Where {obas_part1}.[part_type] Like '2%' Order By {obas_part1}.[part_type]"
dt = cmd.ExecuteReader()
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
trv.BuildTree(dt,"type_name|part_name","","type_name")
trv.Nodes.Insert("加载所有数据",0)
这是加载树的
AfterCheckNode 代码:
Dim trv As WinForm.TreeView = e.Sender
Dim flt As String
Dim flt1 As String
For Each nd As WinForm.TreeNode In e.node.Nodes '同步子节点选中状态
nd.Checked = e.Node.Checked
Next
If e.node.ParentNode IsNot Nothing Then '去掉父节点选中状态
e.node.ParentNode.Checked = False
End If
For Each nd As WinForm.TreeNode In trv.AllNodes
If nd.Checked Then
If nd.Text = "加载所有数据" Then
flt = "{obas_part1}.[part_type] Like '2%'"
End If
If flt > "" Then
flt = flt & " Or " '注意用or而不是And
End If
If nd.Level = 0 Then '注意下面的条件都要用括号括起来
flt = flt & "( type_name = '" & nd.Text & "')"
Else
flt = flt & "( type_name = '" & nd.ParentNode.Text & "' And part_name = '" & nd.Text & "')"
End If
End If
Next
If flt = "" Then
flt = "{obas_part}.[part_no] Is null"
ElseIf flt = "{obas_part1}.[part_type] Like '2%' Or ( type_name = '加载所有数据')" Then
flt = "{obas_part1}.[part_type] Like '2%'"
End If
Dim ids As String
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.C
cmd.CommandText = "Select {obas_part1}.part_no From ({obas_part1} Inner JOIN {obas_part} ON {obas_part}.[part_no] = {obas_part1}. [part_no]) Inner JOIN {obas_part_type} ON {obas_part_type}.[type_no] = {obas_part1}.[part_type] Where " & flt
dt = cmd.ExecuteReader()
If dt.DataRows.Count > 0
For Each dr As DataRow In dt.DataRows
ids = ids & ",'" & dr("part_no") & "'"
Next
ids = ids.Trim(",")
DataTables("obas_part1").LoadFilter = "part_no In (" & ids & ")"
DataTables("obas_part1").Load()
End If
[此贴子已经被作者于2014-4-11 9:09:33编辑过]