0

I am trying to create a ticket system, this part of the system will display all of the acts performing on each specific day. I am also trying to show how many tickets/seats are available. I have a database with all seat locations and a boolean value to show if they are taken or not.

 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

the first part of the program puts all the show dates into a list box, then depending on which one is clicked it shows a different list of acts from my text files. The second part of the program is supposed to use an SQL statement to find all the seat locations which are available. Then it counts the records and then displays the number in a text box.

Object reference not set to an instance of an object

This error appears 4 times and it highlights this line:

sSelectedAssetType = oDataRowView("ShowDate").ToString
chandler
  • 13
  • 6

1 Answers1

0

To get rid of the error, its very likely that somehow oDataRowView is null. You need to check to make sure its not null before you try to convert it to a string. Do something like this:

IF Not isdbnull(oDataRowView)
 oDataRowView = CType(Me.lbxDates.SelectedItem, DataRowView)
End if

As to why you are getting a null value for oDataRowView, that will require you to debug further. Perhaps it could be an issue with PostBack (assuming this is a web page and not winforms.

logixologist
  • 3,856
  • 3
  • 23
  • 43