ADO/ADO.NET - HasRows and Read( ) - Asked By dejawoo Pi on 17-Jan-06 01:55 AM

I have  a datareader, with result of one row (that I have checked with query analyzer). Weird thing that While HasRow shows the true result.. the Read() shows false.  Is not should be also show true. As I know Read() is placed prior to first row. so even if there is one it should work fine. am I wrong? can someone help me with this. Thanx in advance

HowRows and Read - Asked By Kevin Davis on 17-Jan-06 02:55 AM

Try placing the read in a do while loop:

        Do While sqldatareader.Read
            Dim hotel As New Hotel
            hotel.HotelID = sqldatareader("HotelID")
            hotel.HotelName = sqldatareader("HotelName")
            hotelCollection.Add(hotel)
        Loop

Aloha,

Kevin

Kevin, - Asked By dejawoo Pi on 17-Jan-06 03:17 AM

The point is DataReader.Read() returns false, that it never starts the loop. I have checked with Analyzer and Profiler, it works fine the SQL statement returnin one row.  check this link 
http://www.dotnet247.com/247reference/msgs/57/289476.aspx they are discussing same issue but seems noone has come up with solution.... Help Pls.

SET NOCOUNT ON - Asked By F Cali on 17-Jan-06 12:10 PM

Hi dejawoo,

In your stored procedure, try putting the following line right after the declaration of the parameters (after the AS):

SET NOCOUNT ON

So, your stored procedure will look like the following:

CREATE PROCEDURE dbo.TestProc @Param1 INT
AS
SET NOCOUNT ON

... the rest of the stored procedure.

Let us know if it works.
That was the cause - Asked By dejawoo Pi on 18-Jan-06 12:04 AM
http://www.eggheadcafe.com/forums/ForumPost.asp?ID=55711&INTID=10, Anyway  thank you Ronald for giving me valuable  tip. cheers.