此主题相关图片如下:2.jpg
上图左侧为目录树,左下角为刷新该目录树,目录树的Datatable有1500行数据左右,为sql服务器数据源,刷新目录树的代码执行效率非常低,刷新一次要等很长时间,如何才能优化下面这段代码,缩短执行时间?
'2.目录树显示统计数据
For Each nd As WinForm.TreeNode In trv.AllNodes
Dim kg As new String(".",24- nd.Name.Length*2)
Dim sum As Integer
Select nd.Level
Case 0
If nd.Name <> "全市数据" Then
sum = DataTables("特困人员表").SQLCompute("count([_Identify])","县市区 = '" & nd.Name & "'")
Else
sum= DataTables("特困人员表").SQLCompute("count([_Identify])","[_Identify] is not null")
End If
kg = kg & "......"
Case 1
sum = DataTables("特困人员表").SQLCompute("count([_Identify])","县市区 = '" & nd.DataRow("县市区") & "' and 乡镇 = '" & nd.DataRow("乡镇") & "'")
kg = kg & "..."
Case 2
sum = DataTables("特困人员表").SQLCompute("count([_Identify])","县市区 = '" & nd.DataRow("县市区") & "' and 乡镇 = '" & nd.DataRow("乡镇") & "' and 村居 = '" & nd.DataRow("村居") & "'")
End Select
If sum > 0 Then
nd.Text = nd.Name & kg & sum & "人"
End If
Next
[此贴子已经被作者于2017/9/5 17:18:24编辑过]