我想向数据行显示rootid和root名称 [英] I want to show rootid and root name to data rows

查看:62
本文介绍了我想向数据行显示rootid和root名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Quote:

我想向数据行显示RootID和根名称





我尝试过:



 Imports System.Data.SqlClient 
Public Class Treeaccount
Dim con As New SqlConnection(Data Source = FASERVER\YSEFA; Initial Catalog = ECBSQL; Integrated Security = True)
Dim da As New SqlDataAdapter

Private Sub Treeaccount_Load(sender As Object,e As EventArgs)Handles MyBase.Load
Create_TV()
End Sub
Private Sub Create_TV()
TV.Nodes.Clear()
Dim sql As String =select * from tree where parentRoot = -1 order BY ParentRoot
Dim dt As DataTable = RunSql(sql)

Dim TVN As New TreeNode(dt) .Rows(0)(RootName))
TVN.Tag = dt.Rows(0)(RootID)
TV.Nodes.Add(TVN)
nodechild(TVN)
TV.ExpandAll()
TV.SelectedNode = TV.Nodes(0)
End Sub
Private Sub nodechild(Tnode As TreeNode)
Dim dt As DataTable = RunSql(select * from tree where parentRoot =& Tnode.Tag)
For each dr As DataRow in dt.Rows
Dim TVN As New TreeNode(dr(RootName))
TVN.Tag = dr(RootID)
Tnode.Nodes.Add(TVN)
nodechild(TVN)

下一个
结束Sub


私有函数RunSql(SQL As String)As DataTable
Dim dt As New DataTable
da = New SqlDataAdapter(SQL,con)
da.Fill(dt)
返回dt
结束函数

Private Sub TextBox1_TextChanged(sender As Object,e As EventArgs)Handles RootID.TextChanged

End Sub

Private Sub NewBut_Click(sender As Object,e作为EventArgs)处理NewBut.Click
RootID.Text =
RootName.Text =
ParentRoot.Text = TV.SelectedNode.Tag
RootID.Focus()
End Sub

Private Sub savebut_Click(sender As Object,e As EventArgs)处理savebut.Click
Dim cmd As N ew SqlCommand(插入树值(@ RootID,@ RootName,@ ParentRoot),con)
cmd.Parameters.Add(@ RootID,SqlDbType.NVarChar,15).Value = RootID.Text
cmd.Parameters.Add(@ RootName,SqlDbType.NVarChar,255).Value = RootName.Text
cmd.Parameters.Add(@ ParentRoot,SqlDbType.NVarChar,9).Value = ParentRoot.Text

如果con.State = ConnectionState.Closed那么con.Open()
cmd.ExecuteNonQuery()
con.Close()
Create_TV()

End Sub

Private Sub TV_AfterSelect(sender As Object,e As TreeViewEventArgs)处理TV.AfterSelect
RootID.Text = TV.SelectedNode.Tag
RootName.Text = TV.SelectedNode.Text


End Sub
End Class

解决方案

根据评论尝试

  Dim  TVN 作为 新 TreeNode(dt.Rows( 0 )(  RootName)& dt.Rows( 0 )(  RootID))


Quote:

I want to show RootID and Root Name to data Rows



What I have tried:

Imports System.Data.SqlClient
Public Class Treeaccount
    Dim con As New SqlConnection("Data Source=FASERVER\YSEFA;Initial Catalog=ECBSQL;Integrated Security=True")
    Dim da As New SqlDataAdapter

    Private Sub Treeaccount_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Create_TV()
    End Sub
    Private Sub Create_TV()
        TV.Nodes.Clear()
        Dim sql As String = "select * from tree where parentRoot=-1 order BY ParentRoot"
        Dim dt As DataTable = RunSql(sql)

        Dim TVN As New TreeNode(dt.Rows(0)("RootName"))
        TVN.Tag = dt.Rows(0)("RootID")
        TV.Nodes.Add(TVN)
        nodechild(TVN)
        TV.ExpandAll()
        TV.SelectedNode = TV.Nodes(0)
    End Sub
    Private Sub nodechild(Tnode As TreeNode)
        Dim dt As DataTable = RunSql("select * from tree where parentRoot=" & Tnode.Tag)
        For Each dr As DataRow In dt.Rows
            Dim TVN As New TreeNode(dr("RootName"))
            TVN.Tag = dr("RootID")
            Tnode.Nodes.Add(TVN)
            nodechild(TVN)

        Next
    End Sub


    Private Function RunSql(SQL As String) As DataTable
        Dim dt As New DataTable
        da = New SqlDataAdapter(SQL, con)
        da.Fill(dt)
        Return dt
    End Function

    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles RootID.TextChanged

    End Sub

    Private Sub NewBut_Click(sender As Object, e As EventArgs) Handles NewBut.Click
        RootID.Text = ""
        RootName.Text = ""
        ParentRoot.Text = TV.SelectedNode.Tag
        RootID.Focus()
    End Sub

    Private Sub savebut_Click(sender As Object, e As EventArgs) Handles savebut.Click
        Dim cmd As New SqlCommand("insert Into Tree values(@RootID,@RootName,@ParentRoot)", con)
        cmd.Parameters.Add("@RootID", SqlDbType.NVarChar, 15).Value = RootID.Text
        cmd.Parameters.Add("@RootName", SqlDbType.NVarChar, 255).Value = RootName.Text
        cmd.Parameters.Add("@ParentRoot", SqlDbType.NVarChar, 9).Value = ParentRoot.Text

        If con.State = ConnectionState.Closed Then con.Open()
        cmd.ExecuteNonQuery()
        con.Close()
        Create_TV()

    End Sub

    Private Sub TV_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles TV.AfterSelect
        RootID.Text = TV.SelectedNode.Tag
        RootName.Text = TV.SelectedNode.Text


    End Sub
End Class

解决方案

As per the comments try

Dim TVN As New TreeNode(dt.Rows(0)("RootName") & dt.Rows(0)("RootID"))


这篇关于我想向数据行显示rootid和root名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆