-2
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    Try

        connn_start()

        Dim Query As String
        Query = "Select * from abc.abc_list"

        Dim dbcomm = New MySqlCommand(Query, dbconn)
        While dbread.Read 'error is throwing at this point
            Dim DB_VName = dbread.GetString("abc_name")
            cb_V_Name.Items.Add(DB_Name)
        End While

        Connn_stop()

    Catch ex As MySqlException
        MessageBox.Show(ex.Message)

    Finally
        dbconn.Dispose()
    End Try

How to handle this exception?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 1
    possible duplicate of [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Daniel A. White Sep 07 '15 at 01:33
  • 1
    not enough code. - where is `dbread` assigned?? – Daniel A. White Sep 07 '15 at 01:33
  • 1
    You seem to be trying to read from a data reader that you never create. Calling `ExecuteReader` on your command will return a data reader that you can then read from. Make sure that you close it when you're done. – jmcilhinney Sep 07 '15 at 01:56
  • OP needs `Option Explicit On` – oscilatingcretin Sep 07 '15 at 02:40
  • @oscilatingcretin, given that `Option Explicit` is `On` by default, the OP would have had to turn it `Off` explicitly for that to be an issue. I could be wrong, but I'm guessing that `dbread` is actually a field. That's bad in itself mind you, as it should be a local variable. – jmcilhinney Sep 07 '15 at 03:26

1 Answers1

0

add before the read:

SqlDataReader dbread=dbcomm.ExecuteReader();
if (reader.HasRows)
{
  while (reader.Read())
  {
    ...
  }
}
NINtender
  • 109
  • 6