我现在通过服务器名称列表完成了所有工作,但我想通过列出的 True 或 False 值检查 SQL Server 中名为 Compliance 的列来添加 IF 语句。如果为 False,则名称会将文本颜色更改为红色。如果为 True,则名称不会更改文本颜色。我不确定如何在 VB 代码中添加它。我很确定我需要将 IF 语句放入While dr.Read()。我对 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