Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Loading a DataReader
Message
 
To
31/10/2002 09:21:00
Rex Mahel
Realm Software, Llc
Ohio, United States
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
00717293
Message ID:
00717339
Views:
15
Hi Rex,

You need to call the Read method of the DataReader to fetch the first record. You typically put the Read method in a Loop so you can iterate through all the records.
cnn.Open()
dr = cmd.ExecuteReader( _
	CommandBehavior.CloseConnection)
Do While dr.Read()
	lstDemo.Items.Add(String.Format("{0}: {1}, {2}", _
		dr("Au_Id"), dr("Au_lname"), dr("Au_fname")))
Loop
dr.Close()
>All,
>
>Sorry for my previous post, here is the corrected version:
>
>I am trying to load a DataReader from a SQLServer stored procedure. I have to following code:
>
>
>Dim objConnection As SqlConnection
>Dim objCommand As SqlCommand
>Dim objParameter As SqlParameter
>Dim objDR As SqlDataReader
>Try
>	objConnection = New SqlConnection(DBConnectionName)
>	objConnection.Open()
>
>	objCommand = New SqlCommand(LoadPagedStoredProcedure, objConnection)
>	objCommand.CommandType = CommandType.StoredProcedure
>
>		... Set Parameters Here ...
>
>	objDR = objCommand.ExecuteReader(CommandBehavior.CloseConnection)
>
>Catch objException As Exception
>	mObjException = objException
>Catch objSQLException As SqlException
>	mObjException = objSQLException
>End Try
>Return objDR
>
>
>There are no errors, but the DataReader is empty. When I change the DataReader to a DataSet and change the ExecuteReader to a Fill, all works perfectly.
>
>What am I doing wrong?
>
>TIA
>
>Rex
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Reply
Map
View

Click here to load this message in the networking platform