请教:关于treeview控件动态从数据库中绑定节点的问题?
请大家帮忙解决一下啊!我实在找不出该怎么做了?
运行时出现以下错误:(在错误中‘Nindex’是我在数据表中输入的Nodeid数据)
System.Data.SqlClient.SqlException: 列名 'Nindex ' 无效。 46error:System.Data.SqlClient.SqlException: 将 varchar 值 'Nindex ' 转换为数据类型为 int 的列时发生语法错误。
其中我的数据库表中,id int 自动编号
Nodeid char(30) 节点名称
Nodetext varchar(50) 节点文字
parentNodeid char(30) 父节点名称
相关代码如下:
Sub BindNode(ByVal nds As Microsoft.Web.UI.WebControls.TreeNodeCollection, ByVal parentnodeid As String)
Dim conn As New SqlConnection( "user id=sa;password=123456;data source=(local);persist security info=False;initial catalog=niit ")
Dim strsql As String = "select * from bookinfo where parentNodeid= " & parentNodeid
Dim cmd As New SqlCommand(strsql, conn)
conn.Open()
Try
Dim dr As SqlDataReader = cmd.ExecuteReader
Do While dr.Read
Dim tempNode As New Microsoft.Web.UI.WebControls.TreeNode
tempNode.ID = Trim(dr.Item( "Nodeid "))
tempNode.Text = Trim(dr.Item( "Nodetext "))
nds.Add(tempNode)
Call BindNode(tempNode.Nodes, Trim(dr.Item( "Nodeid ")))
Loop
Catch ex As Exception
Response.Write( "error: " + ex.ToString)
End Try
conn.Close()
End Sub