Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

get values from query

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pelegk1 - 08 Jul 2007 22:04 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.