Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 617
  • Last Modified:

empty dataset

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

Response.Write(users.Tables.Count);

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")
}

0
Mr_Shaw
Asked:
Mr_Shaw
  • 2
  • 2
1 Solution
 
rpkhareCommented:
There can be a DataTable without rows in a DataSet.

Check this:
http://msdn.microsoft.com/en-us/library/system.data.datatablecollection.collectionchanged.aspx

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.
0
 
Gyanendra SinghArchitectCommented:
try
0
 
Gyanendra SinghArchitectCommented:
try this

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

But this does not mean that DataSet is empty. There might be a table with no rows.
0
 
Mr_ShawAuthor Commented:
thanks
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now