Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 未为“字符串”和“控件”类型定义运算符“&”_Mysql_Vb.net - Fatal编程技术网

Mysql 未为“字符串”和“控件”类型定义运算符“&”

Mysql 未为“字符串”和“控件”类型定义运算符“&”,mysql,vb.net,Mysql,Vb.net,我正在构建一个VB.Net应用程序来实时检查生产区域中机器的状态。我想在显示器上显示区域布局,如果机器状态为1,则显示绿色,如果为2,则显示红色,如果是其他东西,则显示橙色。我有下面的代码,但它不起作用,因为它说操作符&不是为类型控件定义的,我用它来声明我的标签数组。有人能告诉我我做错了什么吗?我是VB.Net中的乞丐 Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

我正在构建一个VB.Net应用程序来实时检查生产区域中机器的状态。我想在显示器上显示区域布局,如果机器状态为1,则显示绿色,如果为2,则显示红色,如果是其他东西,则显示橙色。我有下面的代码,但它不起作用,因为它说操作符&不是为类型控件定义的,我用它来声明我的标签数组。有人能告诉我我做错了什么吗?我是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 & ""

如果您试图在sqlquery中使用字符串连接标签控件,则需要从标签中获取文本,请参见下文

更改此项:

Dim sqlquery = "select IDEstado from Maquinas where IDMaquina = " & labels(i) & ""
为此:

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

你知道你在哪一行得到错误吗?可能Console.WriteLinelabelsi需要一个.ToString或.Text。`&labelsi&`是的,它有帮助。还有一个问题,有些标签不是绿色的,所有的机器现在都有状态1,当我创建控制台时。writeline的值查询接收到的那些不是绿色的,writeline没有显示任何内容。有什么原因可以在大多数标签上使用,而在其他几个标签上不使用?我不确定我是否理解你的问题。如果您在有问题的地方发布一个带有代码示例的单独问题会更好。事实上,我在select查询中想要的是这样的:Dim sqlquery=select IDEstado from Maquinas where IDMaquina=i,但如果我这样说,它会在where子句中显示未知列“i”