empty dataset

Posted on 2008-10-27
Last Modified: 2013-12-17
I have a dataset which I am testing if it is null, my code is

if (userDataSet.Tables.Count == 0)
response.write ("Dataset is empty")

When nothing happened I decided to test if my IF condition was working, so I wrote


The code returned 1.

This is not correct since I know there are no rows in my table. Is the table heading counted as the first row in Tables.Count.

If this is so, should I write

if (userDataSet.Tables.Count == 1)
response.write ("Dataset is empty")

Question by:Mr_Shaw
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Accepted Solution

rpkhare earned 500 total points
ID: 22811419
There can be a DataTable without rows in a DataSet.

Check this:

Note that:
DataSet.Tables.Count returns number of tables in dataset.
Whereas, DataSet.Tables[0].Rows.Count returns number of rows in the first table.
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22811451
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22811455
try this

userDataSet.Tables[0].Rows.count ==0
response.write ("Dataset is empty")

Expert Comment

ID: 22811509

But this does not mean that DataSet is empty. There might be a table with no rows.

Author Closing Comment

ID: 31510247

Featured Post

Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question