Determine is a dataset is empty

  • Thread starter Thread starter martin
  • Start date Start date
M

martin

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
 
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..
 
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 said:
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 said:
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
 
if you are using dataset then u should be able to use the count property to
check the total count

--

Regards,

HD
martin said:
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 said:
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 said:
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
 
Back
Top