get values from query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i have a simple query
SELECT User_Pass,id FROM Users
and i want using ExecuteReader to get the values of this 2 columns into
parameters.
when i try to do :
Dim reader As SqlDataReader = myCommand.ExecuteReader()
and then
reader.GetString(0) i get :
Invalid attempt to read when no data is present
while for suer i know that there is a data
what to do?
thnaks in advane
peleg
 
pelegk1 said:
i have a simple query
SELECT User_Pass,id FROM Users
and i want using ExecuteReader to get the values of this 2 columns into
parameters.
when i try to do :
Dim reader As SqlDataReader = myCommand.ExecuteReader()
and then
reader.GetString(0) i get :
Invalid attempt to read when no data is present
while for suer i know that there is a data
what to do?


You've forgotten to call the Read method on the SqlDataReader:
http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.read.aspx

Dim reader As SqlDataReader = myCommand.ExecuteReader()
reader.Read()
reader.GetString(0)
 
i have a simple query
SELECT User_Pass,id FROM Users
and i want using ExecuteReader to get the values of this 2 columns into
parameters.
when i try to do :
Dim reader As SqlDataReader = myCommand.ExecuteReader()
and then
reader.GetString(0) i get :
Invalid attempt to read when no data is present
while for suer i know that there is a data
what to do?
thnaks in advane
peleg

You must execute the statement

reader.Read

before attempting to access the results with GetString etc. The
ExecuteReader method only creates a reader object, it doesn't retrieve
any data.

HTH
 
Back
Top