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
Mark Rae [MVP] - 08 Jul 2007 22:09 GMT
>i have a simple query
> SELECT User_Pass,id FROM Users
[quoted text clipped - 7 lines]
> 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.rea
d.aspx
Dim reader As SqlDataReader = myCommand.ExecuteReader()
reader.Read()
reader.GetString(0)

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
Phil H - 08 Jul 2007 22:15 GMT
> i have a simple query
> SELECT User_Pass,id FROM Users
[quoted text clipped - 9 lines]
> 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