0
我在如何檢索數據庫中每個表格的2個字段時遇到了問題。我有3個表保存在我的MS Access中,即:RegularPassenger,DisablePassenger和VIPPassenger,每個表都有兩個字段,分別是SeatsNo和Filled。檢索MS ACCESS中的所有表格
這種情況是,我想讓用戶看看他們所選的座位是否已經保留,這表示一個彩色按鈕,如果它已被保留。我到目前爲止所做的代碼是我只能檢索一個表。
的代碼是:
Imports System
Imports System.Data.OleDb
Public Class SeatsAlignment
Dim con As New System.Data.OleDb.OleDbConnection
Dim cmd As New System.Data.OleDb.OleDbCommand
Dim CntRw As Integer
Private Function CheckReservation(ByVal StNo As String) As Boolean
If con.State = ConnectionState.Open Then con.Close()
con = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\laptop\Documents\Trial\Sample.accdb")
con.Open()
cmd.CommandType = CommandType.Text
cmd.CommandText = "Select Count(*) From RegularPassenger Where [email protected] And [email protected]"
cmd.Parameters.Add("@StNo", OleDb.OleDbType.VarChar, 10).Value = StNo
cmd.Parameters.Add("@StFld", OleDb.OleDbType.VarChar, 10).Value = "RESERVED"
cmd.Connection = con
CntRw = cmd.ExecuteScalar()
cmd.Parameters.Clear()
cmd.Dispose()
con.Close()
con.Dispose()
Return IIf(CntRw > 0, True, False)
End Function
Private Sub SeatsAlignment_Load(sender As Object, e As EventArgs) Handles MyBase.Load
RPS.Enabled = False
DPS.Enabled = False
VPS.Enabled = False
TextBox1.Enabled = False
TextBox2.Enabled = False
Dim Buttons As New List(Of Button) From {A3, A4, A5, A6, A7, B3, B4, B5, B6, B7, _
C3, C4, C5, C6, C7, D3, D4, D5, D6, D7, E3, E4, E5, E6, E7, F3, F4, F5, F6, F7}
For Each btn As Button In Buttons
If Me.CheckReservation(btn.Name) Then
btn.BackColor = Color.Firebrick
btn.Enabled = False
End If
Next
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
If MsgBox("Are you sure you want to EXIT?", vbYesNo + vbQuestion, _
"Philippine Sweets Airline") = vbYes Then
Me.Close()
End If
End Sub
End Class
而且我不知道是什麼確切的代碼放就行了14來檢索所有3個表。
是什麼名稱的用途或目的,類型= 1和標誌= 0? – 2014-10-06 10:14:00
我應該改變我的代碼從「選擇計數(*)從RegularPassenger Where SeatNo = @ StNo和Filled = @ StFld」更改爲「SELECT Name from MSysObjects WHERE Type = 1 AND Flags = 0」? – 2014-10-06 10:15:21