我試圖創建票證系統,系統的這一部分將顯示所有在每個特定日執行的行爲。我也試圖顯示有多少票/座位可用。我有一個包含所有座位位置和布爾值的數據庫,以顯示它們是否被佔用。錯誤 - 未將對象引用設置爲對象的實例
Public ds As New DataSet 'used to store the basic elements of the database
Public con As New OleDb.OleDbConnection 'used to connect to the database
Public provider As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
Public datafile As String = "Resources/database.accdb" 'database location and version
Public da As OleDb.OleDbDataAdapter
Public sqlstatement As String
Public connString As String = provider & datafile
lbxActs.Items.Clear()
Dim oDataRowView As DataRowView
Dim sSelectedAssetType As String
ds.Clear()
con.ConnectionString = connString
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()
oDataRowView = CType(Me.lbxDates.SelectedItem, DataRowView)
sSelectedAssetType = oDataRowView("ShowDate").ToString
lbxActs.Items.AddRange(IO.File.ReadAllLines("Resources/" & sSelectedAssetType & ".txt"))
con.Close()
ds.Clear()
con.ConnectionString = connString
con.Open() 'Open connection to the database
sqlstatement = "SELECT * FROM [Seats" & sSelectedAssetType & "] WHERE [Available] = True "
da = New OleDb.OleDbDataAdapter(sqlstatement, con)
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
tbxLeftS.Text = recordCount
該計劃的第一部分,將所有演出日期,列表框,然後根據其中的一個被點擊它顯示的行爲從我的文本文件不同的列表。程序的第二部分應該使用SQL語句來查找所有可用的座位位置。然後對記錄進行計數,然後在文本框中顯示數字。
Object reference not set to an instance of an object
此錯誤出現4次,它突出了這一行:
sSelectedAssetType = oDataRowView("ShowDate").ToString
看起來像'oDataRowView(「ShowDate」)'是'沒有' – Ian
也許沒有選擇 –
我剛剛編輯的代碼,我忘了包括一些東西 – chandler