reading error from table - vb.net- using OleDbDataReader

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • questionit
    Contributor
    • Feb 2007
    • 553

    reading error from table - vb.net- using OleDbDataReader

    Hi

    When i run the program, i get error on the statement inside Do While Loop. The piece of code from my application is:


    Code:
    Dim selectString As String
            selectString = "Select ContactName, Address from Customers"
    
            Dim cmd As OleDbCommand = New OleDbCommand(selectString, con)
            Dim reader As OleDbDataReader
    
            reader = cmd.ExecuteReader()
    
            Do While reader.Read() = True
                strName = reader("ContactName")
                strAddress = reader("Address")
            Loop
    Object reference not set to an instance of an object
    Last edited by tlhintoq; Jun 22 '09, 05:00 PM. Reason: [CODE] ... your code here ... [/CODE] tags added
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Object reference not set to an instance of an object
    You need to initialize all your variables to *something* before you use them.
    If you look at your variables after the break, Visual Studio will show you which one(s) are null.

    Comment

    Working...