473,804 Members | 3,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do you test for an empty dataset

I have written a simple web service that basically takes a value input
by a user and returns a dataset with all related data found in a
database.

In my client app use this code to get the data from the web service :

Dataset dsData = ws.wsmethod(par ameter);

And whether any data is returned or not, I don't get an error, so I need
to test if the dataset is empty or not to see if any data has been
returned.

Can anybody help me out with this?
Cheers,

Mike

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #1
6 19055
JV
Mike, question 1 is whether the returned dataset reference can be null. If
so, you need to check for that first.

If not, then be aware that a DataSet contains a collection of DataTable
objects. For each DataTable object, you can access the Rows collection and
check its Count property.
"Mike P" <mi*******@gmai l.com> wrote in message
news:ej******** *****@TK2MSFTNG P12.phx.gbl...
I have written a simple web service that basically takes a value input
by a user and returns a dataset with all related data found in a
database.

In my client app use this code to get the data from the web service :

Dataset dsData = ws.wsmethod(par ameter);

And whether any data is returned or not, I don't get an error, so I need
to test if the dataset is empty or not to see if any data has been
returned.

Can anybody help me out with this?
Cheers,

Mike

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 17 '05 #2
JV,

Using if (ds == null) doesn't seem to work, so I'm having to use this
syntax to check if the Dataset is empty or not :

string str = dsTransResult.T ables["tbl"].Rows.Count.ToS tring();

Is this the standard way of doing this, it seems a bit long winded just
to check for an empty dataset?
Cheers,

Mike

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #3
You got it right. (Although not sure that the ToString() is for in this
context.)

You could always wrap this in some utility/helper method.

"Mike P" <mi*******@gmai l.com> wrote in message
news:OB******** *****@TK2MSFTNG P12.phx.gbl...
JV,

Using if (ds == null) doesn't seem to work, so I'm having to use this
syntax to check if the Dataset is empty or not :

string str = dsTransResult.T ables["tbl"].Rows.Count.ToS tring();

Is this the standard way of doing this, it seems a bit long winded just
to check for an empty dataset?
Cheers,

Mike

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 17 '05 #4
"Peter Rilling" <pe***@nospam.r illing.net> wrote in message
news:eP******** ******@TK2MSFTN GP10.phx.gbl...
You got it right. (Although not sure that the ToString() is for in this
context.)

You could always wrap this in some utility/helper method.

"Mike P" <mi*******@gmai l.com> wrote in message
news:OB******** *****@TK2MSFTNG P12.phx.gbl...
JV,

Using if (ds == null) doesn't seem to work, so I'm having to use this
syntax to check if the Dataset is empty or not :

string str = dsTransResult.T ables["tbl"].Rows.Count.ToS tring();

Is this the standard way of doing this, it seems a bit long winded just
to check for an empty dataset?
Cheers,

Mike

Do you need to go that far, can't you just test the dataset's Tables.Count? Or
might it have tables that are present but of no use?

--

Joe (MVP)

https://mvp.support.microsoft.com/pr...8-8741D22D17A5
Nov 17 '05 #5
if you are looking to see if the Data set object is empty ie null or has no
tables, then
ds.Tables["my table name "] with throw an exception if "my table name" is
not in your data set.
So what you need to do is check if ds is null, then see if the
ds.Tables.count >0, see if it has your table ds.Tables.Conta ins("my table
name"), now you can look at the table and see if it has any rows
ds.Tables["my table name"].Rows.Count >0
Aaron

"Mike P" wrote:
JV,

Using if (ds == null) doesn't seem to work, so I'm having to use this
syntax to check if the Dataset is empty or not :

string str = dsTransResult.T ables["tbl"].Rows.Count.ToS tring();

Is this the standard way of doing this, it seems a bit long winded just
to check for an empty dataset?
Cheers,

Mike

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 17 '05 #6
Joe Fawcett wrote:
"Peter Rilling" <pe***@nospam.r illing.net> wrote in message
news:eP******** ******@TK2MSFTN GP10.phx.gbl...
You got it right. (Although not sure that the ToString() is for in this
context.)

You could always wrap this in some utility/helper method.

"Mike P" <mi*******@gmai l.com> wrote in message
news:OB****** *******@TK2MSFT NGP12.phx.gbl.. .
JV,

Using if (ds == null) doesn't seem to work, so I'm having to use this
syntax to check if the Dataset is empty or not :

string str = dsTransResult.T ables["tbl"].Rows.Count.ToS tring();

Is this the standard way of doing this, it seems a bit long winded just
to check for an empty dataset?
Cheers,

Mike


Do you need to go that far, can't you just test the dataset's Tables.Count? Or
might it have tables that are present but of no use?


Tables.Count counts the number of "tables". There probably is at least
one table, but that might be empty. Tables[0].Rows.Count counts the
number of actual rows in the first table (and ignores any other tables
that might be present).
--
Hans Kesting
Nov 17 '05 #7

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

Similar topics

2
26737
by: Andreas Palm | last post by:
I have a dataset that has DBNull in certain columns, now when I write out this one to XML, I only get the columns as elements that do have data in it. However I do need also the empty colums as empty elements in the XML. How to do that ? I don't understand why there is no simple option to specify the output format, or did I miss something ? regards andreas
2
4130
by: Phil Galey | last post by:
How do you get around the problem of empty tables in a dataset not being included when you do a WriteXML? When you later read the data back into a new dataset, those tables are gone, because they never got saved to the XML file. Only tables containing one or more records get saved to the XML file. Thanks.
2
18494
by: Ron | last post by:
Can anyone tell me how to check and see if a dataset is empty? I am writing a search function that returns a dataset and binds it to a datagrid. If no data is found, I would like to make the grid invisible and have a label appear stating that no data was found. Any suggestions? Thanks,
3
1746
by: martin | last post by:
Hi, I am having trouble determining if my dataset is empty. I have function that populates a dataset from a database and then retuens it. If the database contains no data then the dataset will be completely empty, and then when I go to databind() it to a combo box and error will be throw. What I whould like to do is check the dataset from code to see if it is empty.
22
4238
by: EMW | last post by:
Hi, I managed to create a SQL server database and a table in it. The table is empty and that brings me to my next chalenge: How can I get the info in the table in the dataset to go in an empty SQL table? Is there a short way like the FILL method to get data into the dataset or do I have to read each datarow in the table and write it one at the time to the
6
2703
by: Ben Finney | last post by:
Howdy all, Summary: I'm looking for idioms in unit tests for factoring out repetitive iteration over test data. I explain my current practice, and why it's unsatisfactory. When following test-driven development, writing tests and then coding to satisfy them, I'll start with some of the simple tests for a class.
7
3472
by: Dabbler | last post by:
I'm using an ObjectDataSource with a stored procedure and am getting the following error when trying to update (ExecuteNonQuery): System.Data.SqlClient.SqlException: Procedure or Function 'UpdateRegistrant' expects parameter '@EMail', which was not supplied. The field value was null in the database and not changed in the FormView so is null going back into the stored procedure. I'm stumped and would greatly appreciate any suggestions.
3
6696
by: AAJ | last post by:
Hi all A quick question on Datasets..... I populate a dataset from a SQL SERVER 2000 database via a data adapter. I then use the dataset to populate member variables of my class. I know the datatype of a column in the database, so I use convert. to convert the results in to the same datatype within my class i.e.
2
2053
by: Shum | last post by:
Hi! i have a question.. I'm filling a dataset from a table in which some rows are empty, i dont want those empty records to be filled in the dataset.. Does any one know how to restrict it to only non empty records.. ??
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10577
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10320
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10077
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9150
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5521
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4299
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.