473,406 Members | 2,619 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,406 software developers and data experts.

Determine is a dataset is empty

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.

can anybody please point me in the direction of how to do this.

many thanks in advance.

cheers

martin
Nov 18 '05 #1
3 1709
a dataset always contains datatable(s)....
if your dataset has only one datatable (ie results of one select query)
all you have to do is something like this

int rowCount = myDataSet.Tables[0].Rows.Count

check the count and see if its zero... ie no records found..

--
Regards,

HD

"martin" <ma***************@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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.

can anybody please point me in the direction of how to do this.

many thanks in advance.

cheers

martin

Nov 18 '05 #2
Hi,

Thanks for that. Although I'm not sure if the syntax

int rowCount = myDataSet.Tables[0].Rows.Count

is correct. The way I found to get the number of rows in the first table of
a dataset was to iterate through then and count them in a

For ... Each loop

would be interested in a way to do this in one line similar to what you had
above.

cheers

martin.

"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:OK**************@TK2MSFTNGP11.phx.gbl...
a dataset always contains datatable(s)....
if your dataset has only one datatable (ie results of one select query)
all you have to do is something like this

int rowCount = myDataSet.Tables[0].Rows.Count

check the count and see if its zero... ie no records found..

--
Regards,

HD

"martin" <ma***************@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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.

can anybody please point me in the direction of how to do this.

many thanks in advance.

cheers

martin


Nov 18 '05 #3
if you are using dataset then u should be able to use the count property to
check the total count

--

Regards,

HD
"martin" <ma***************@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi,

Thanks for that. Although I'm not sure if the syntax

int rowCount = myDataSet.Tables[0].Rows.Count

is correct. The way I found to get the number of rows in the first table of a dataset was to iterate through then and count them in a

For ... Each loop

would be interested in a way to do this in one line similar to what you had above.

cheers

martin.

"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:OK**************@TK2MSFTNGP11.phx.gbl...
a dataset always contains datatable(s)....
if your dataset has only one datatable (ie results of one select query)
all you have to do is something like this

int rowCount = myDataSet.Tables[0].Rows.Count

check the count and see if its zero... ie no records found..

--
Regards,

HD

"martin" <ma***************@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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.

can anybody please point me in the direction of how to do this.

many thanks in advance.

cheers

martin



Nov 18 '05 #4

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

Similar topics

1
by: John | last post by:
Hi All, When I delete the last record from my dataset and then WriteXML() to the file; the Table itself, in the xml file, is removed. I need to prevent the table structure from being deleted if...
2
by: Iwan Petrow | last post by:
Hi, I have two tables with relation: Table1: T1_id T2_id (foreign key,allow null) ..... Table2
2
by: vooose | last post by:
Consider a server executing "SELECT * FROM Settings WHERE UserID=@UserID" which is loaded into a DataSet and then we use dataSet.GetXML() to send this to the requesting client. The client...
22
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...
3
by: jaYPee | last post by:
is there a way to know if the form is edited or not after calling addnew? Me.BindingContext(DsStudentCourse1, "Students").AddNew() because i got an error after closing the form. because in my...
2
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...
7
by: David | last post by:
Hi, using C# asp.net 1.1 I am having a problem. If I use the code below, but have null passed as the PostingGuid, then by the time I get to fill the dataset, I have "an object is not set to...
2
by: ccbryan | last post by:
Hi folks... .NET newbie I admit. I'm running VS 2005 version 8 on .NET platform 2.0.50727 SP1. How can you tell if a query has returned an empty dataset to a SQLReader or a DataTable? I am running...
3
by: John Sheppard | last post by:
Hello there, I have the following code; I do this as a work around for a dataset.haschanges method which doesnt appear to work correctly either For Each dt As DataTable In myDs.Tables If Not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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,...
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.