gpt4 book ai didi

mysql - 运算符 '&' 没有为类型 'String' 和 'Control' 定义

转载 作者:行者123 更新时间:2023-11-29 02:20:59 25 4
gpt4 key购买 nike

我正在构建一个 VB.Net 应用程序来实时检查生产区域中机器的状态。我想在监视器中显示区域布局,如果机器状态为 1,则将其显示为绿色,如果为 2,则显示为红色,如果是其他状态,则显示为橙色。我有以下代码,但它不起作用,因为它说运算符 & 没有为类型 Control 定义,我用它来声明我的标签数组。如果我做错了什么,有人可以告诉我吗? (我是 VB.Net 的初学者)

 Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim labels() As Control = {Label1, Label2, Label3, Label4, Label5, Label6, Label7, Label8, Label9, Label10, Label11, Label12, Label13, Label14, Label15, Label16, Label17, Label18, Label19, Label20, Label21, Label22,
Label23, Label24, Label25, Label26, Label27, Label28, Label29, Label30, Label31, Label32, Label33, Label34, Label35, Label36, Label37, Label38, Label39, Label40, Label41, Label42, Label43, Label44, Label45, Label46,
Label47, Label48, Label49, Label50, Label51, Label52, Label53, Label54, Label55, Label56, Label57, Label58, Label59, Label60, Label61, Label62, Label63, Label64, Label65, Label66, Label67, Label68, Label69, Label70,
Label71, Label72}
Dim estado As Integer

Try
con.Open()
For i = 0 To 71
Console.WriteLine(labels(i))
Dim sqlquery = "select IDEstado from Maquinas where IDMaquina = " & labels(i) & ""
Dim myCommand As New MySqlCommand()
myCommand.Connection = con
myCommand.CommandText = sqlquery
Dim objReader As MySqlDataReader = myCommand.ExecuteReader
If objReader.Read = True Then
estado = objReader("IDEstado")

If estado = 1 Then
labels(i).BackColor = System.Drawing.Color.Green
ElseIf estado = 2 Then
labels(i).BackColor = System.Drawing.Color.Red
Else
labels(i).BackColor = System.Drawing.Color.DarkOrange
End If
End If
objReader.Close()
Next
con.Close()
Finally
End Try

End Sub

最佳答案

您需要使用控件的 Text 属性,同时按照您发布的代码像下面一样连接它,您实际上是在尝试将字符串与控件连接起来,因此出现错误。

Dim sqlquery = "select IDEstado from Maquinas where IDMaquina = " & labels(i).Text & ""

关于mysql - 运算符 '&' 没有为类型 'String' 和 'Control' 定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31875246/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com