Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

empty dataset

Posted on 2008-10-27
5
Medium Priority
?
615 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
[X]
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
5 Comments
 
LVL 8

Accepted Solution

by:
rpkhare earned 2000 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

704 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