Re: dr.Read()
From: William \(Bill\) Vaughn (billvaRemoveThis_at_nwlink.com)
Date: 02/14/05
- Previous message: William \(Bill\) Vaughn: "Re: Changes in a DataGrid don't always take"
- In reply to: Andy: "Re: dr.Read()"
- Next in thread: Jim Rand: "Re: dr.Read()"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 14 Feb 2005 13:25:13 -0800
This behavior is by design. When you execute any query that does not return
a rowset, the DataReader returns as "closed" (Dr.Read = False). Step to the
next resultset or add SET NOCOUNT ON in your query or SP to drop rowsetless
resultsets.
hth
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
"Andy" <Andy@discussions.microsoft.com> wrote in message
news:796F58E6-877F-4A42-BF16-CC24305D6724@microsoft.com...
> Mr. Vaughn:
>
> Please forgive me: but did I miss your response?
>
> Thanks
> Andy
>
> "William (Bill) Vaughn" wrote:
>
>> See my reply on rowset-less resultsets...
>>
>> --
>> ____________________________________
>> William (Bill) Vaughn
>> Author, Mentor, Consultant
>> Microsoft MVP
>> www.betav.com
>> Please reply only to the newsgroup so that others can benefit.
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>> __________________________________
>>
>> "Andy" <Andy@discussions.microsoft.com> wrote in message
>> news:FA03BDF3-F02D-4BA7-9F7F-EE7184F0A311@microsoft.com...
>> > Hello Everyone:
>> >
>> > I have a feeling this is very basic, and something I am just
>> > overlooking.
>> > The dr.Read() ALWAYS is being translated to false in the code below. I
>> > print
>> > out the sSQL statement using the watch window, and paste that into
>> > Query
>> > Analyzer: and I confirm the data does indeed exist. What am I
>> > missing?
>> > Why, regardless of the data, does my dr.Read() alway equal false?
>> >
>> > -----------------------------------------------------------------------------------------------
>> > CODE SNIPPET
>> > -----------------------------------------------------------------------------------------------
>> > sSQL = "SELECT i_OrderID FROM tOrder WHERE sPOrder = " + sPONumber;
>> > SqlConnection oConn = new SqlConnection(connStr());
>> > SqlCommand oCommand = new SqlCommand(sSQL, oConn);
>> > oConn.Open();
>> > SqlDataReader dr = oCommand.ExecuteReader();
>> > if(dr.Read())
>> > {
>> > ...Code Removed
>> > }
>> > else
>> > {
>> > ...Code Removed
>> > }
>>
>>
>>
- Previous message: William \(Bill\) Vaughn: "Re: Changes in a DataGrid don't always take"
- In reply to: Andy: "Re: dr.Read()"
- Next in thread: Jim Rand: "Re: dr.Read()"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|