0

一直在关注此站点上的一个问题,尝试更改标签背景色在 .mdb 数据库中可见,使用 SQL 将 VB.Net 与数据库连接。我有一个座位计划设置为表格中的网格,使用座位标签。如果座位代码显示在预订数据库中,则标签应变为红色(预订座位时添加记录)否则,如果它没有返回任何记录,则标签保持绿色。

Private Sub CheckFriday()
    Dim Friday(11, 20) As Control

    'Friday Row A
    Friday(1, 1) = FA1
    Friday(1, 2) = FA2
    Friday(1, 3) = FA3
    Friday(1, 4) = FA4
    Friday(1, 5) = FA5
    Friday(1, 6) = FA6
    Friday(1, 7) = FA7
    Friday(1, 8) = FA8
    Friday(1, 9) = FA9
    Friday(1, 10) = FA10
    Friday(1, 11) = FA11
    Friday(1, 12) = FA12
    Friday(1, 13) = FA13
    Friday(1, 14) = FA14
    'Friday Row B
    Friday(2, 1) = FB1
    Friday(2, 2) = FB2
    Friday(2, 3) = FB3
    Friday(2, 4) = FB4
    Friday(2, 5) = FB5
    Friday(2, 6) = FB6
    Friday(2, 7) = FB7
    Friday(2, 8) = FB8
    Friday(2, 9) = FB9
    Friday(2, 10) = FB10
    Friday(2, 11) = FB11
    Friday(2, 12) = FB12
    Friday(2, 13) = FB13
    Friday(2, 14) = FB14
    Friday(2, 15) = FB15
    Friday(2, 16) = FB16
    'Friday Row C
    Friday(3, 1) = FC1
    Friday(3, 2) = FC2
    Friday(3, 3) = FC3
    Friday(3, 4) = FC4
    Friday(3, 5) = FC5
    Friday(3, 6) = FC6
    Friday(3, 7) = FC7
    Friday(3, 8) = FC8
    Friday(3, 9) = FC9
    Friday(3, 10) = FC10
    Friday(3, 11) = FC11
    Friday(3, 12) = FC12
    Friday(3, 13) = FC13
    Friday(3, 14) = FC14
    Friday(3, 15) = FC15
    Friday(3, 16) = FC16
    Friday(3, 17) = FC17
    'Friday Row D
    Friday(4, 1) = FD1
    Friday(4, 2) = FD2
    Friday(4, 3) = FD3
    Friday(4, 4) = FD4
    Friday(4, 5) = FD5
    Friday(4, 6) = FD6
    Friday(4, 7) = FD7
    Friday(4, 8) = FD8
    Friday(4, 9) = FD9
    Friday(4, 10) = FD10
    Friday(4, 11) = FD11
    Friday(4, 12) = FD12
    Friday(4, 13) = FD13
    Friday(4, 14) = FD14
    Friday(4, 15) = FD15
    Friday(4, 16) = FD16
    Friday(4, 17) = FD17
    Friday(4, 18) = FD18
    Friday(4, 19) = FD19
    'Friday Row E
    Friday(5, 1) = FE1
    Friday(5, 2) = FE2
    Friday(5, 3) = FE3
    Friday(5, 4) = FE4
    Friday(5, 5) = FE5
    Friday(5, 6) = FE6
    Friday(5, 7) = FE7
    Friday(5, 8) = FE8
    Friday(5, 9) = FE9
    Friday(5, 10) = FE10
    Friday(5, 11) = FE11
    Friday(5, 12) = FE12
    Friday(5, 13) = FE13
    Friday(5, 14) = FE14
    Friday(5, 15) = FE15
    Friday(5, 16) = FE16
    Friday(5, 17) = FE17
    Friday(5, 18) = FE18
    Friday(5, 19) = FE19
    Friday(5, 20) = FE20
    'Friday Row F
    Friday(6, 1) = FF1
    Friday(6, 2) = FF2
    Friday(6, 3) = FF3
    Friday(6, 4) = FF4
    Friday(6, 5) = FF5
    Friday(6, 6) = FF6
    Friday(6, 7) = FF7
    Friday(6, 8) = FF8
    Friday(6, 9) = FF9
    Friday(6, 10) = FF10
    Friday(6, 11) = FF11
    Friday(6, 12) = FF12
    Friday(6, 13) = FF13
    Friday(6, 14) = FF14
    Friday(6, 15) = FF15
    Friday(6, 16) = FF16
    Friday(6, 17) = FF17
    Friday(6, 18) = FF18
    Friday(6, 19) = FF19
    Friday(6, 20) = FF20
    'Friday Row G
    Friday(7, 1) = FG1
    Friday(7, 2) = FG2
    Friday(7, 3) = FG3
    Friday(7, 4) = FG4
    Friday(7, 5) = FG5
    Friday(7, 6) = FG6
    Friday(7, 7) = FG7
    Friday(7, 8) = FG8
    Friday(7, 9) = FG9
    Friday(7, 10) = FG10
    Friday(7, 11) = FG11
    Friday(7, 12) = FG12
    Friday(7, 13) = FG13
    Friday(7, 14) = FG14
    Friday(7, 15) = FG15
    Friday(7, 16) = FG16
    Friday(7, 17) = FG17
    Friday(7, 18) = FG18
    Friday(7, 19) = FG19
    'Friday Row H
    Friday(8, 1) = FH1
    Friday(8, 2) = FH2
    Friday(8, 3) = FH3
    Friday(8, 4) = FH4
    Friday(8, 5) = FH5
    Friday(8, 6) = FH6
    Friday(8, 7) = FH7
    Friday(8, 8) = FH8
    Friday(8, 9) = FH9
    Friday(8, 10) = FH10
    Friday(8, 11) = FH11
    Friday(8, 12) = FH12
    Friday(8, 13) = FH13
    Friday(8, 14) = FH14
    Friday(8, 15) = FH15
    Friday(8, 16) = FH16
    Friday(8, 17) = FH17
    Friday(8, 18) = FH18
    Friday(8, 19) = FH19
    'Friday Row J
    Friday(9, 1) = FJ1
    Friday(9, 2) = FJ2
    Friday(9, 3) = FJ3
    Friday(9, 4) = FJ4
    Friday(9, 5) = FJ5
    Friday(9, 6) = FJ6
    Friday(9, 7) = FJ7
    Friday(9, 8) = FJ8
    Friday(9, 9) = FJ9
    Friday(9, 10) = FJ10
    Friday(9, 11) = FJ11
    Friday(9, 12) = FJ12
    Friday(9, 13) = FJ13
    Friday(9, 14) = FJ14
    Friday(9, 15) = FJ15
    Friday(9, 16) = FJ16
    Friday(9, 17) = FJ17
    Friday(9, 18) = FJ18
    Friday(9, 19) = FJ19
    'Friday Row K
    Friday(10, 1) = FK1
    Friday(10, 2) = FK2
    Friday(10, 3) = FK3
    Friday(10, 4) = FK4
    Friday(10, 5) = FK5
    Friday(10, 6) = FK6
    Friday(10, 7) = FK7
    Friday(10, 8) = FK8
    Friday(10, 9) = FK9
    Friday(10, 10) = FK10
    Friday(10, 11) = FK11
    Friday(10, 12) = FK12
    Friday(10, 13) = FK13
    Friday(10, 14) = FK14
    Friday(10, 15) = FK15
    Friday(10, 16) = FK16
    Friday(10, 17) = FK17
    Friday(10, 18) = FK18
    Friday(10, 19) = FK19
    'Friday Row L
    Friday(11, 1) = FL1
    Friday(11, 2) = FL2
    Friday(11, 3) = FL3
    Friday(11, 4) = FL4
    Friday(11, 5) = FL5
    Friday(11, 6) = FL6
    Friday(11, 7) = FL7
    Friday(11, 8) = FL8
    Friday(11, 9) = FL9
    Friday(11, 10) = FL10
    Friday(11, 11) = FL11
    Friday(11, 12) = FL12
    Friday(11, 13) = FL13
    Friday(11, 14) = FL14
    Friday(11, 15) = FL15
    Dim A As Integer = 0
    Dim x As Integer
    Dim y As Integer
    con.ConnectionString = dbProvider & dbSource
    con.Open() 'opens the connection to the database
    For y = 1 To 11
        For x = 1 To 20
            SQL = "SELECT * FROM Sales where SEAT_ID = '" & Friday(x, y) & "'"
            da = New OleDb.OleDbDataAdapter(Sql, con) 'create a data adapter to store the filtered data using the SQL code
            MsgBox(Sql)
            da.Fill(ds, A)
            A = A + 1
            Dim recordCount As Integer
            recordCount = ds.Tables(A).Rows.Count
            MsgBox(recordCount)

            If recordCount = 1 Then
                Friday(x, y).BackColor = Color.Red
            Else
                Friday(x, y).BackColor = Color.Green
            End If
        Next x
    Next y

End Sub

我收到此错误:

错误 1 ​​运算符 '&' 没有为类型 'String' 和 'System.Windows.Forms.Control' 定义。C:\Users\Connor Loughlin\Desktop\WindowsApplication1\WindowsApplication1\SeatingPlan.vb 238 23 SADS 预订系统

非常感谢您的建议或反馈,VB 肯定不是我最擅长的主题。

谢谢您的帮助!

4

1 回答 1

1

您使用的是对象而不是它所代表的文本。如果您的对象支持,请尝试使用 .toString。

SQL = "SELECT * FROM Sales where SEAT_ID = '" & Friday(x, y).toString & "'"

于 2013-05-09T14:50:02.353 回答