我正在创建一个预订学校表演门票的计划。在这部分代码中,我试图显示所有演出的可用日期,这些日期来自数据库。然后根据选择的日期,我改变座位计划的颜色以指示座位是否被拍摄。
Private Sub Seating_Plan_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ds.Clear()
con.Open()
sqlstatement = "SELECT ShowDate FROM AvailableDates"
da = New OleDb.OleDbDataAdapter(sqlstatement, con)
da.Fill(ds, "dates")
lbxDates.DataSource = ds.Tables("Dates")
lbxDates.DisplayMember = "ShowDate"
lbxDates.ValueMember = "ShowDate"
con.Close()
End Sub
Private Sub lbxDates_SelectedValueChanged(sender As Object, e As EventArgs) Handles lbxDates.SelectedValueChanged
Dim oDataRowView As DataRowView = CType(Me.lbxDates.SelectedItem, DataRowView)
If Not IsDBNull(oDataRowView) Then
oDataRowView = CType(Me.lbxDates.SelectedItem, DataRowView)
End If
sSelectedAssetType = oDataRowView("ShowDate").ToString
For Each btn As Control In Me.Controls
If checkSeats(btn.Name()) = "True" Then
btn.BackColor = Color.LightGreen
Else
btn.BackColor = Color.Coral
End If
If btn.Name() = "lblStage" Then
btn.BackColor = Color.Transparent
ElseIf btn.Name() = "btnClose" Then
btn.BackColor = Color.Transparent
ElseIf btn.Name() = "btnBookBack" Then
btn.BackColor = Color.Transparent
ElseIf btn.Name() = "pbxBob" Then
btn.BackColor = Color.Transparent
ElseIf btn.Name() = "lblTitle" Then
btn.BackColor = Color.Transparent
ElseIf btn.Name() = "Button1" Then
btn.BackColor = Color.Transparent
ElseIf btn.Name() = "lblTaken" Then
btn.BackColor = Color.LightGreen
ElseIf btn.Name() = "lblTaken2" Then
btn.BackColor = Color.Coral
ElseIf btn.Name() = "lblConcertDate" Then
btn.BackColor = Color.Transparent
ElseIf btn.Name() = "txtDate" Then
btn.BackColor = Color.White
ElseIf btn.Name() = "lblShowDate" Then
btn.BackColor = Color.Transparent
ElseIf btn.Name() = "lbxDates" Then
btn.BackColor = Color.White
End If
Next
End Sub
Public Function checkSeats(ByVal seatRef As String)
con.Close()
ds.Clear()
con.ConnectionString = connString
con.Open() 'Open connection to the database
sqlstatement = "SELECT * FROM " & "Seats" & sSelectedAssetType & " WHERE [Available] = True AND [Seat_Location] ='" & seatRef & "'"
da.Fill(ds, "Seats") 'Fill the data adapter
con.Close()
Dim recordCount, x As Short
recordCount = 0
x = 0
recordCount = ds.Tables("seats").Rows.Count
If recordCount = 0 Then
Return False
Else
Return True
End If
End Function
连接数据库的所有数据都在一个模块中,并且工作正常,我得到错误的行是这个:
sSelectedAssetType = oDataRowView("ShowDate").ToString