我参考"动态加载数据的例子",想动态加载来自SQL SERVER的表:tab_wjk.但是主窗口的afterload中的代码,测试时报错,请问是什么原因.请帮我检查一下错在哪里?还是外部表的代码不一样?
窗口afterload代码如下:
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.CommandText = "SELECT DISTINCT 分类号,保管期限,年度 From {tab_wjk}"
dt = cmd.ExecuteReader()
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
trv.BuildDataTree(dt, "","分类号", "保管期限","年度")
NodeMouseDoubleClick的代码如下:
Dim Value()As String
Dim Filter As string
Value = e.Node.FullPath.Split("\")
Select Case e.Node.Level
Case 0
Filter ="[分类号] = '" & Value(0) & "'"
Case 1
Filter ="[分类号] = '" & Value(0) & "' And [保管期限] = '" & Value(1) & "'"
Case 2
Filter ="[分类号] = '" & Value(0) & "' And [保管期限] = '" & Value(1) & "' And [年度] = '" & Value(2) & "'"
End Select
DataTables("tab_wjk").LoadFilter = Filter
DataTables("tab_wjk").Load()
[此贴子已经被作者于2009-3-16 13:26:34编辑过]
我用的是内部表,而你用外部表,所有不能这样:
SELECT DISTINCT 分类号,保管期限,年度 From {订单}
而应该:
SELECT DISTINCT 分类号,保管期限,年度 From 订单
SELECT DISTINCT 分类号,保管期限,年度 From tab_wjk 这段代码我测试过了,是没问题的.是不是其它代码有问题?
你用的是外部数据源,必须给SQLCommand指定数据源名称,否则肯定出错:
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.ConnectionName = "数据源名称"
cmd.CommandText = "SELECT DISTINCT 分类号,保管期限,年度 From tab_wjk"
dt = cmd.ExecuteReader()
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
trv.BuildDataTree(dt, "","分类号", "保管期限","年度")