Question datareader notimplementedException?

ulynen

Member
Joined
Feb 18, 2015
Messages
22
Programming Experience
5-10
the code snippet gives me 2 problems:
Dim cReader As OleDbDataReader
cReader = cmd.ExecuteReader()
End Try


stext = ""


Do While cReader.Read()
stext = stext & ";" & cReader.GetString(0)
Loop

in the do while loop creader is reported as not declared. I don't understand why because I copied code from supposedly working examples.

When I run in debug I get system.notimplementedException error. This only happened after I added the the datareader code.
 
there is a bit before the snippet

cmd.CommandText = "qselphone"
cmd.Parameters.AddWithValue("parPhone", "6475311136")
cmd.CommandType = CommandType.StoredProcedure
 
Hi,

The "Give Away" to your problem is that "End Try" statement before you try to read the DataReader. Since you have not posted all the code here which defines what you are doing I very much suspect that you have broken the rule of "Variable Scope".

In your case if you have declared the cReader variable within the boundary of a Try/Catch Block then that DataReader is only visible within the portion of the Try/Catch block where it was declared. To demonstrate:-

This example would be fine since it uses the DataReader within the Scope in which it was declared:-
Try
  Dim myReader As OleDbDataReader = someCommand.ExecuteReader
  'Get some information from a Database
  Do While myReader.Read
    'Do Some Work with the Reader
  Loop
Catch ex As Exception
  MessageBox.Show(ex.Message)
End Try


However, this example would FAIL with the error you are getting since it uses the DataReader Outside of the Scope in which it was declared:-
Try
  Dim myReader As OleDbDataReader = someCommand.ExecuteReader
  'Get some information from a Database
Catch ex As Exception
  MessageBox.Show(ex.Message)
End Try
 
Do While myReader.Read
  'Do Some Work with the Reader
Loop


Hope that helps.

Cheers,

Ian
 
Back
Top