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

Mr_ShawAsked:
Who is Participating?
 
rpkhareConnect With a Mentor Commented:
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
All Courses

From novice to tech pro — start learning today.