0

サーバー名のリストですべてが機能するようになりましたが、SQL Server の Compliance という列を、リストされている True または False の値でチェックして、IF ステートメントを追加したいと考えています。False の場合、Name はテキストの色を赤に変更します。True の場合、Name はテキストの色を変更しません。それをVBコード側に追加する方法がわかりません。While dr.Read()内に IF ステートメントを入れる必要があると確信しています。私はVB.Netにかなり慣れていないので、テキストの色を変更するVBコードがわかりません。

ここに私のVBコードがあります、

Sub loadData()
    'clear treeview control
    TreeViewGroups.Nodes.Clear()

    'fetch owner data and save to in memory table
    Dim sqlConn As New System.Data.SqlClient.SqlConnection((ConfigurationManager.ConnectionStrings("SOCT").ConnectionString))
    Dim strSqlSecondary As String = "SELECT [Name] FROM [dbo].[ServerOwners] where SecondaryOwner like @uid order by [name]"

    'Getting a list of True or False from Compliance column
    Dim strSqlCompliance As String = "SELECT [Compliance] FROM [dbo].[ServerOwners] where SecondaryOwner like @uid order by [name]"

    Dim cmdSecondary As New System.Data.SqlClient.SqlCommand(strSqlSecondary, sqlConn)

    Dim cmdCompliance As New System.Data.SqlClient.SqlCommand(strSqlCompliance, sqlConn)

    cmdSecondary.Parameters.AddWithValue("@uid", TNN.NEAt.GetUserID())

    cmdCompliance.Parameters.AddWithValue("@uid", TNN.NEAt.GetUserID())

    Dim dr As System.Data.SqlClient.SqlDataReader
    Try
        sqlConn.Open()
        Dim root As TreeNode
        Dim rootNode As TreeNode
        Dim firstNode As Integer = 0
        'Load Primary Owner Node
        'Create RootTreeNode

        dr = cmdSecondary.ExecuteReader()
        If dr.HasRows Then
            'Load Secondary Owner Node
            'Create RootTreeNode
            root = New TreeNode("Secondary Owner", "Secondary Owner")
            TreeViewGroups.Nodes.Add(root)
            root.SelectAction = TreeNodeSelectAction.None

            rootNode = TreeViewGroups.Nodes(firstNode)
            'populate the child nodes
            While dr.Read()
                Dim child As TreeNode = New TreeNode(dr("Name"), dr("Name"))
                rootNode.ChildNodes.Add(child)
                child.SelectAction = TreeNodeSelectAction.None
            End While
            dr.Close()
            cmdSecondary.Dispose()
        End If

        'check if treeview has nodes
        If TreeViewGroups.Nodes.Count = 0 Then
            noServers()
        End If
    Catch ex As Exception
        hide()
        PanelError.Visible = True
        LabelError.Text = ex.ToString()
    Finally
        sqlConn.Dispose()
    End Try
End Sub
4

2 に答える 2