Solved

empty dataset

Posted on 2008-10-27
5
608 Views
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

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
Comment
Question by:Mr_Shaw
  • 2
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
rpkhare earned 500 total points
ID: 22811419
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
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22811451
try
0
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22811455
try this

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

Expert Comment

by:rpkhare
ID: 22811509
BondinASP,

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

Author Closing Comment

by:Mr_Shaw
ID: 31510247
thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now