Discussion:
ADO.NET, Sql2K5 - true hack...
Peter Osucha
2007-04-21 18:43:45 UTC
Permalink
David L. Penton
2007-04-21 20:37:59 UTC
Permalink
Is there some reason why you can't return an empty resultset in the cases where there is nothing to return for sets #2 and #3? That
seems like a better thing to do.

&_david++;

Peter Osucha wrote:
> This seems like a true 'hack'. Perhaps someone can give me a better way
> to do this.
>
> I have an SQL2K5 sp that returns up to 3 datasets (before telling me to
> not return more than 1 dataset, please let me know of a better way to do
> this! J). The first dataset is always returned. Due to the arguments
> used to call the sp, there is a chance that the normal 'second' dataset
> won't be returned, the normal 'third' dataset won't be returned, or that
> neither the normal 'second' nor the normal 'third' dataset will be
> returned.
>
> In order to tell in my C# app which dataset I am working with (I keep
> looking for new datasets with a
>
> 'while ( dr.NextResult ( ) ) {}'
>
> block of code), I am using a 'hack' of adding an extra column to the
> returned dataset ('FromTabel1' or 'FromTable2', etc.) so that I can
> check the datareader.GetOrdinal() to see which dataset I am really
> dealing with.
>
> If I have explained well enough what I am doing, can someone please
> provide me a better way to check a returned dataSet for my purpose?
>
> Peter

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Peter Osucha
2007-04-22 01:00:31 UTC
Permalink
Peter Osucha
2007-04-23 13:41:56 UTC
Permalink
Efran Cobisi
2007-04-23 13:52:13 UTC
Permalink
Hi Peter,

To me it makes perfect sense the *DataReader does not hold a resultset
index state. By design, IDataReader is a forward only reader; it tends
to not hold any state while running, in order to achieve the best
possible performance. Btw it doesn't hold the active row index neither.

HTH,

Efran Cobisi
http://www.cobisi.com

Peter Osucha wrote:
> David,
>
> I fixed the sps this morning - yes, your suggestion was the right one.
> However, I'm still hoping for a bit more. Perhaps you have another
> suggestion?
>
> This one sp I'm calling actually returns 4 datasets. So my C# code
> processed the first dataset and then goes into this while (
> dr.NextResult ( ) ) loop. Before the loop, I set a counter variable
> (loopIdx) to '1' - loopIdx gets incremented each time a 'NextResult' is
> found. I then use a Switch() block to act on the specific NextResult
> DataSet. It seems like there should be a better way to check the
> dataset I'm working with then just using this loopIdx arrangement where
> I, as a developer, need to 'remember' the order of the returned
> DataSets.
>
> Peter
>
>
> -----Original Message-----
> From: Discussion relating to the specifics of the C# and Managed C++
> languages [mailto:DOTNET-***@DISCUSS.DEVELOP.COM] On Behalf Of Peter
> Osucha
> Sent: Saturday, April 21, 2007 9:01 PM
> To: DOTNET-***@DISCUSS.DEVELOP.COM
> Subject: Re: [DOTNET-CX] ADO.NET, Sql2K5 - true hack...
>
> Yes, David. Indeed it does. I didn't even think of that. That makes
> much
> more sense.
>
> Thanks.
>
> Peter(--;)
>
> -----Original Message-----
> From: Discussion relating to the specifics of the C# and Managed C++
> languages [mailto:DOTNET-***@DISCUSS.DEVELOP.COM] On Behalf Of David L.
> Penton
> Sent: Saturday, April 21, 2007 4:38 PM
> To: DOTNET-***@DISCUSS.DEVELOP.COM
> Subject: Re: [DOTNET-CX] ADO.NET, Sql2K5 - true hack...
>
> Is there some reason why you can't return an empty resultset in the
> cases
> where there is nothing to return for sets #2 and #3? That seems like a
> better thing to do.
>
> &_david++;
>
> Peter Osucha wrote:
>
>> This seems like a true 'hack'. Perhaps someone can give me a better
>> way to do this.
>>
>> I have an SQL2K5 sp that returns up to 3 datasets (before telling me
>> to not return more than 1 dataset, please let me know of a better way
>> to do this! J). The first dataset is always returned. Due to the
>> arguments used to call the sp, there is a chance that the normal
>> 'second' dataset won't be returned, the normal 'third' dataset won't
>> be returned, or that neither the normal 'second' nor the normal
>> 'third' dataset will be returned.
>>
>> In order to tell in my C# app which dataset I am working with (I keep
>> looking for new datasets with a
>>
>> 'while ( dr.NextResult ( ) ) {}'
>>
>> block of code), I am using a 'hack' of adding an extra column to the
>> returned dataset ('FromTabel1' or 'FromTable2', etc.) so that I can
>> check the datareader.GetOrdinal() to see which dataset I am really
>> dealing with.
>>
>> If I have explained well enough what I am doing, can someone please
>> provide me a better way to check a returned dataSet for my purpose?
>>
>> Peter
>>
>
> ===================================
> This list is hosted by DevelopMentor® http://www.develop.com
>
> View archives and manage your subscription(s) at http://discuss.develop.com
>

--
Efran Cobisi
Technical Project Leader
MCP, MCTS: SQL Server 2005
***@qbgroup.it <mailto:***@qbgroup.it>



QBGROUP spa
Corso del Popolo, 8/C - 35131 Padova - Italy
tel. +39 049.8763444 - fax +39 049.8787700
www.qbgroup.it <http://www.qbgroup.it>

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Peter Osucha
2007-04-25 01:29:50 UTC
Permalink
Ryan Heath
2007-04-24 08:14:07 UTC
Permalink
On 4/23/07, Peter Osucha <***@proteindiscovery.com> wrote:
> This one sp I'm calling actually returns 4 datasets. So my C# code
> processed the first dataset and then goes into this while (
> dr.NextResult ( ) ) loop. Before the loop, I set a counter variable


>From the information you gave, a switch seems to be "overgeneralised"
without any benefit.

Is this your code?

int i = 0;
do
{
switch(i)
{
case 0: // handle 1st data
case 1: // handle 2nd data
case 2: // handle 3rd data
case 3: // handle 4th data
default: // throw exception (unexpected) ;)
}
i++;
} while ( dr.NextResult());


Personally I would prefer

// handle 1st data
if ( !dr.NextResult()) // throw exception
// handle 2nd data
if ( !dr.NextResult()) // throw exception
// handle 3rd data
if ( !dr.NextResult()) // throw exception
// handle 4th data

Since the order is hard coded in your SP, it make sense to hard code
it in your C# code as well, the switch makes it hard to read, IMO

// Ryan


On 4/23/07, Peter Osucha <***@proteindiscovery.com> wrote:
> David,
>
> I fixed the sps this morning - yes, your suggestion was the right one.
> However, I'm still hoping for a bit more. Perhaps you have another
> suggestion?
>
> This one sp I'm calling actually returns 4 datasets. So my C# code
> processed the first dataset and then goes into this while (
> dr.NextResult ( ) ) loop. Before the loop, I set a counter variable
> (loopIdx) to '1' - loopIdx gets incremented each time a 'NextResult' is
> found. I then use a Switch() block to act on the specific NextResult
> DataSet. It seems like there should be a better way to check the
> dataset I'm working with then just using this loopIdx arrangement where
> I, as a developer, need to 'remember' the order of the returned
> DataSets.
>
> Peter
>
>
> -----Original Message-----
> From: Discussion relating to the specifics of the C# and Managed C++
> languages [mailto:DOTNET-***@DISCUSS.DEVELOP.COM] On Behalf Of Peter
> Osucha
> Sent: Saturday, April 21, 2007 9:01 PM
> To: DOTNET-***@DISCUSS.DEVELOP.COM
> Subject: Re: [DOTNET-CX] ADO.NET, Sql2K5 - true hack...
>
> Yes, David. Indeed it does. I didn't even think of that. That makes
> much
> more sense.
>
> Thanks.
>
> Peter(--;)
>
> -----Original Message-----
> From: Discussion relating to the specifics of the C# and Managed C++
> languages [mailto:DOTNET-***@DISCUSS.DEVELOP.COM] On Behalf Of David L.
> Penton
> Sent: Saturday, April 21, 2007 4:38 PM
> To: DOTNET-***@DISCUSS.DEVELOP.COM
> Subject: Re: [DOTNET-CX] ADO.NET, Sql2K5 - true hack...
>
> Is there some reason why you can't return an empty resultset in the
> cases
> where there is nothing to return for sets #2 and #3? That seems like a
> better thing to do.
>
> &_david++;
>
> Peter Osucha wrote:
> > This seems like a true 'hack'. Perhaps someone can give me a better
> > way to do this.
> >
> > I have an SQL2K5 sp that returns up to 3 datasets (before telling me
> > to not return more than 1 dataset, please let me know of a better way
> > to do this! J). The first dataset is always returned. Due to the
> > arguments used to call the sp, there is a chance that the normal
> > 'second' dataset won't be returned, the normal 'third' dataset won't
> > be returned, or that neither the normal 'second' nor the normal
> > 'third' dataset will be returned.
> >
> > In order to tell in my C# app which dataset I am working with (I keep
> > looking for new datasets with a
> >
> > 'while ( dr.NextResult ( ) ) {}'
> >
> > block of code), I am using a 'hack' of adding an extra column to the
> > returned dataset ('FromTabel1' or 'FromTable2', etc.) so that I can
> > check the datareader.GetOrdinal() to see which dataset I am really
> > dealing with.
> >
> > If I have explained well enough what I am doing, can someone please
> > provide me a better way to check a returned dataSet for my purpose?
> >
> > Peter
>
> ===================================
> This list is hosted by DevelopMentor(r) http://www.develop.com
>
> View archives and manage your subscription(s) at http://discuss.develop.com
>

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Peter Osucha
2007-04-24 14:31:32 UTC
Permalink
Ray Tayek
2007-04-26 18:32:02 UTC
Permalink
Loading...