473,401 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Urgent : Populate a dataset from a stored proc in .NET 2.0

Hi all,

I'm sorry I'm reposting this but the original was urgent and I do need
closure on this.

I'm calling a stored proc which does 4 "selects" and then I populate a
dataset looping through the dr using a dr.NextResult() but the stored proc
may not return any results for one or more Select stetments. When this
happens, a table is not returned so the dataset.Fill() does not populate
conatin 4 tables which then each bind to a grid - the nett result is that
the relevant gridview may not show the correct data.

Now when I do a dr.NextResult(), I don't know which table data is being
returned

How can I call a stored proc passing back a table for each Select
irrespective of whether there is data or not?

Regards
John.

Feb 17 '06 #1
5 2092
"John" <a@b.c> wrote in message
news:O%****************@TK2MSFTNGP14.phx.gbl...
How can I call a stored proc passing back a table for each Select
irrespective of whether there is data or not?


Are you populating a DataReader or a DataSet?

A DataReader has a HasRows property. If it's false, there are no rows, so
move onto the next one.

A DataSet has at least one table, which has a Rows collection. If Rows.Count
is 0, it's empty, so move on to the next one.
Feb 18 '06 #2
Hi,

I'm populating a datareader using cm.ExecuteReader()

The problem is with the mutliple selects within my stored proc. I could call
it one time and get four resultsets hence dr.NextResult 4 times but the next
time I call it I may only receive two resultsets hence dr.Nextresult() twice
but now I don't know from which select statements these resultsets
originate.

I need a way for the stored proc to pass back an empty result set from the
select statements that don't return data. At least then I can still bind to
grid and the grid can "be aware" of my empty table structure.

Any ideas?

Regards
John.

"Mark Rae" <ma**@markN-O-S-P-A-M.co.uk> wrote in message
news:ux**************@TK2MSFTNGP12.phx.gbl...
"John" <a@b.c> wrote in message
news:O%****************@TK2MSFTNGP14.phx.gbl...
How can I call a stored proc passing back a table for each Select
irrespective of whether there is data or not?


Are you populating a DataReader or a DataSet?

A DataReader has a HasRows property. If it's false, there are no rows, so
move onto the next one.

A DataSet has at least one table, which has a Rows collection. If
Rows.Count is 0, it's empty, so move on to the next one.

Feb 18 '06 #3
you should design your proc better, so you can tell.

some ideas:

have the 1 column of each select identity the result set name.
check for existance of a unique col in each result set.
have a dummy select if the select is skipped
before each select do a select returning the next result identification.

-- bruce (sqlwork.com)
"John" <a@b.c> wrote in message news:eN*************@TK2MSFTNGP15.phx.gbl...
Hi,

I'm populating a datareader using cm.ExecuteReader()

The problem is with the mutliple selects within my stored proc. I could
call it one time and get four resultsets hence dr.NextResult 4 times but
the next time I call it I may only receive two resultsets hence
dr.Nextresult() twice but now I don't know from which select statements
these resultsets originate.

I need a way for the stored proc to pass back an empty result set from the
select statements that don't return data. At least then I can still bind
to grid and the grid can "be aware" of my empty table structure.

Any ideas?

Regards
John.

"Mark Rae" <ma**@markN-O-S-P-A-M.co.uk> wrote in message
news:ux**************@TK2MSFTNGP12.phx.gbl...
"John" <a@b.c> wrote in message
news:O%****************@TK2MSFTNGP14.phx.gbl...
How can I call a stored proc passing back a table for each Select
irrespective of whether there is data or not?


Are you populating a DataReader or a DataSet?

A DataReader has a HasRows property. If it's false, there are no rows, so
move onto the next one.

A DataSet has at least one table, which has a Rows collection. If
Rows.Count is 0, it's empty, so move on to the next one.


Feb 18 '06 #4
"John" <a@b.c> wrote in message news:eN*************@TK2MSFTNGP15.phx.gbl...
I need a way for the stored proc to pass back an empty result set from the
select statements that don't return data. At least then I can still bind
to grid and the grid can "be aware" of my empty table structure.


I've already told you how to do this by using a DataSet.

1) Return the data from your SP into a DataSet instead of a DataReader

2) Count the number of Tables in the DataSet - each table corresponds to the
results of the SELECT statements in your SP

3) Interrogate the Rows.Count method of each Table in the DataSet - if its
value is 0, then that particular query has not returned any data.

What else do you need to know...?
Feb 18 '06 #5
Hi Mark,

A rather late reply but thanks a lot for your suggested solution - I do now
get the table structure whether or not data is contained in it.

Regards
John.

"Mark Rae" <ma**@markN-O-S-P-A-M.co.uk> wrote in message
news:ee**************@TK2MSFTNGP10.phx.gbl...
"John" <a@b.c> wrote in message
news:eN*************@TK2MSFTNGP15.phx.gbl...
I need a way for the stored proc to pass back an empty result set from
the select statements that don't return data. At least then I can still
bind to grid and the grid can "be aware" of my empty table structure.


I've already told you how to do this by using a DataSet.

1) Return the data from your SP into a DataSet instead of a DataReader

2) Count the number of Tables in the DataSet - each table corresponds to
the results of the SELECT statements in your SP

3) Interrogate the Rows.Count method of each Table in the DataSet - if its
value is 0, then that particular query has not returned any data.

What else do you need to know...?

Feb 20 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dianna | last post by:
I have a datafeed coming from another Database which I am populating into a Dataset. I want to take the dataset and insert all the rows into a Sql Table. So far I have an 'insert stored proc' and...
1
by: Jawahar Rajan | last post by:
Is it possible for a Dataset that is added to a C# project to be based on a stored Procedure? Can I use either a OracleClient or Microsoft Oracle Client? Any help is appreciated. Jawahar
3
by: Mike P | last post by:
Is it possible to return a dataset from a stored procedure, or would you need to write the SQL in your .cs file to return the dataset? Any assistance would be really appreciated. Cheers, ...
2
by: Mike Hutton | last post by:
I have a rather odd problem. I have a SP which uses temp. tables along the way, and then returns a table of results: CREATE PROCEDURE dbo.usp_myproc( @pNameList VARCHAR(6000) ) AS
3
by: Yul | last post by:
Hi, We are in the process of designing an ASP.NET app, where a user will enter some 'Customer ID' to be queried in the database. If the ID is valid, several stored procedures will be called to...
1
by: Sheldon Penner | last post by:
I have been trying to build a web form using the SQL Data Adapter Configuration Wizard to create a dataset based on a parameterized stored procedure. I find that if I select "Use existing stored...
1
by: amjad | last post by:
i am posting below code i am not sure how to call parametrized store procedure and fill the grid. .... I have store procedure which pull the info from sql server 2005 using asp.net 1.1... that...
3
by: Jon Vaughan | last post by:
I have a client side dataset that is made up from a stored proc, I also have a web service that returns a dataset from this stored proc. But when I call the web service and try and store them in an...
2
by: cookie0311 | last post by:
Hi I am trying to place three DropDownLists inside a Repeater, each DLL is dependent on it’s previous DDL’s selection. I’m developing in asp.net and VB. An Initial DDL (inside the repeater) needs...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.