Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim dic As new Dictionary(Of String,Winform.TreeNode)
Dim nd As WinForm.TreeNode
Dim pd As WinForm.TreeNode
Dim cmd As New SQLCommand
Dim drs As DataTable
cmd.CommandText = "SELECT DISTINCT 编码,名称,上级编码 From {组织机构}"
drs = cmd.ExecuteReader
For Each dr As DataRow In drs
If dr.IsNull("上级编码") = False Then
If dic.ContainsKey(dr("上级编码")) Then
pd = dic(dr("上级编码"))
nd = pd.Nodes.add(dr("编码"),dr("编码")+dr("名称"))
dic.add(dr("编码"),nd)
End If
Else
nd = trv.Nodes.add(dr("编码"),dr("名称"))
dic.add(dr("编码"),nd)
End If
If dr("分支机构") = True
nd.BackColor= color.Gainsboro
nd.ForeColor = color.white
End If
Next
保存代码下出现如下提示:
编译错误:expression is of type 'datatable',which is not a collection type.
错误代码:for each dr as datarow in drs
请各位大师帮看看,是怎么回事呀?