Connecting Tech Pros Worldwide Forums | Help | Site Map

reading error from table - vb.net- using OleDbDataReader

Site Addict
 
Join Date: Feb 2007
Posts: 553
#1: Jun 22 '09
Hi

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


Expand|Select|Wrap|Line Numbers
  1. Dim selectString As String
  2.         selectString = "Select ContactName, Address from Customers"
  3.  
  4.         Dim cmd As OleDbCommand = New OleDbCommand(selectString, con)
  5.         Dim reader As OleDbDataReader
  6.  
  7.         reader = cmd.ExecuteReader()
  8.  
  9.         Do While reader.Read() = True
  10.             strName = reader("ContactName")
  11.             strAddress = reader("Address")
  12.         Loop
Object reference not set to an instance of an object

tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,779
#2: Jun 22 '09

re: reading error from table - vb.net- using OleDbDataReader


Quote:
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.
Reply

Tags
oledbdatareader error