title: "Object Reference not Set to an Instance of an Object" when trying to read from MySQL
body: <p>I've been trying to finish up this assignment, due tomorrow, since we got it a few hours ago. Our class was never really taught VB, we just did a brief overview of the very basics of the language and then were told to go copy the code on our assignments and fill in the rest.</p>
  
  <p>At the moment I'm stuck with an error, which you can see in the title, which is preventing me from finishing up the rest of my program. I've looked around for solutions, but they haven't been very helpful due to my complete lack of knowledge of VB and Visual Studio. (I normally code in Java with Eclipse.)</p>
  
  <p>If anyone can explain what's causing this error and how to avoid it in the future that would help a lot. Thanks for any replies.</p>
  
  <pre><code>Imports System.Data
  Imports MySql.Data.MySqlClient
  
  Public Class inventoryUpdate_form
  Dim quantity As Integer
  Dim quantityList As List(Of Integer)
  Dim isbn As Integer
  Dim isbnList As List(Of Integer)
  
  Public Sub refreshData(first As Boolean)
      'Establish connection to the DB.
      Dim connection As MySqlConnection = New MySqlConnection
      connection.ConnectionString = "server=ERASED;port=ERASED;user id=ERASED;password=ERASED;database=ERASED"
  
      Try
          connection.Open()
  
          ' Clear the quantity and isbn lists before adding new data.
          Try
              quantityList.Clear()
          Catch e As NullReferenceException
          End Try
  
          Try
              isbnList.Clear()
          Catch e As NullReferenceException
          End Try
  
  
          ' Build a query
          Dim query As String
          query = "SELECT book.title, inventory.quantity, book.ISBN FROM book JOIN inventory ON book.ISBN = inventory.ISBN JOIN store ON inventory.store_id = store.store_id WHERE store.city = 'Fredericton' AND inventory.quantity &gt; 0 ORDER BY book.title ASC"
  
          ' Run the query.
          Dim cmd As New MySqlCommand(query, connection)
          Try
              Dim dataReader As MySqlDataReader = cmd.ExecuteReader
              Dim title As String
  
              While dataReader.Read()
                  title = dataReader("title")
                  ComboBox1.Items.Add(title)
                  quantity = dataReader("quantity")
                  quantityList.Add(quantity)
                  isbn = dataReader("ISBN")
                  isbnList.Add(isbn)
              End While
  
              dataReader.Close()
          Catch e As Exception
              MessageBox.Show("Data Reader error: " &amp; e.Message)
          End Try
      Catch e As MySqlException
          ' If an error occurs while connecting to the DB then show the error message.
          MessageBox.Show("Cannot connect to the database: " &amp; e.Message)
      Finally
          ' Close and dispose of the connection to the DB.
          connection.Close()
          connection.Dispose()
      End Try
  End Sub
  
  Private Sub inventoryUpdate_form_Load(sender As Object, e As EventArgs) Handles MyBase.Load
      refreshData(True)
  End Sub
  End Class
  </code></pre>
  
  <p>The error is being shown on this try-catch:</p>
  
  <pre><code>' Run the query.
  Dim cmd As New MySqlCommand(query, connection)
  Try
      Dim dataReader As MySqlDataReader = cmd.ExecuteReader
      Dim title As String
  
      While dataReader.Read()
          title = dataReader("title")
          ComboBox1.Items.Add(title)
          quantity = dataReader("quantity")
          quantityList.Add(quantity)
          isbn = dataReader("ISBN")
          isbnList.Add(isbn)
      End While
  
      dataReader.Close()
  Catch e As Exception
      MessageBox.Show("Data Reader error: " &amp; e.Message)
  End Try
  </code></pre>
  
  <p>That's all I know about the error. I've been looking around for some sort of stack trace, but all I've found is this unhelpful block of text which is a bit too messy to paste here so here you go: <a href="http://pastebin.com/nGqw6V8R" rel="nofollow">http://pastebin.com/nGqw6V8R</a></p>