if Dataset.HasRows=true then
dataset contains data otherwise empty
Login to rate this answer.
Gavin
Answered On : Feb 16th, 2006
What you mean is...
if(Dataset.HasRows)
{
//do whatever
}
Login to rate this answer.
Nandagopal
Answered On : Feb 25th, 2006
Hi
HasRows property is only for DataReader objects. For DataSet you can check whether it has a DataTable or not .. since the DataSet is a collection of DataTable you can check whether it has loaded a table or not using the following code
DataSet dt=
new DataSet(); if (dt.Tables.Count>0) // has tables in it{
}
else // otherwise it is empty{
}

2 Users have rated as useful.
Login to rate this answer.
first two are wrong there is nothing a property like DataSet.HasRows in dataset
third one is right answer to say
Login to rate this answer.
Guest
Answered On : Mar 2nd, 2006
first two are wrong there is nothing a property like DataSet.HasRows in dataset
third one is right answer to say
Login to rate this answer.
inxs
Answered On : Apr 3rd, 2006
All above answers are wrong.
Use,
DataSet_objectName.Tables[0].Rows.Count > 0
Login to rate this answer.
prakhar
Answered On : Apr 6th, 2006
the above ans is wrong as dataset is empty , it will throw error while acessing the first table . so the third is correct answere.
Login to rate this answer.
Omar
Answered On : Apr 17th, 2006
Hi
Checking the dataset like:
if(DataSetObj.Tables[0].Rows.Count> 0)
is right only if you use another "if" statement above it, which is:
if(DataSetObj.Tables.Count > 0)
Regards

1 User has rated as useful.
Login to rate this answer.
Ujjwal Prakash
Answered On : Apr 21st, 2006
Absolutly Right..
To check that if a dataset has data or not we will have to first check if it has any table or not and then we ll have to look into the tables to check the row count.
eg:
if (ds.Tables.Count==0)
{
Console.Write("Empty Dataset");
}
else
{
oreach(DataTable dt in ds)
{}
Login to rate this answer.
Srinivas
Answered On : Apr 25th, 2006
I think we have an method like IsNothing.Using that we can find That dataset has some data or notike :-- DataSet ds = new DataSet() if not IsNothing(ds) { TRUE block;}
Login to rate this answer.
Dhejo
Answered On : May 16th, 2006
None of the answer seems completly correct. First check if(dataset== null)
then check of dataset.Tables == null if these checks are not made exception will occur when u check dataset.Tables.count or dataset.Tables[0].Rows.Count

1 User has rated as useful.
Login to rate this answer.
omi
Answered On : May 24th, 2006
hi,
Forget all answers this is check and true
DataSet ds=
new DataSet();
if(ds.Tables.Count ==0)
{
MessageBox.Show("There are "+ds.Tables.Count.ToString()+"Tables");
}
sqlDataAdapter1.Fill(ds,"hello");
if(ds.Tables.Count>0)
{
MessageBox.Show("There are "+ds.Tables.Count.ToString()+"Tables");
}
Login to rate this answer.
Shipra
Answered On : Jun 6th, 2006
u can directly comapre dataset to null or counting the tables like in below case...
if(dsExample==null || dsExample.Tables.Count==0){ //empty dataset}
else{//not empty}
Login to rate this answer.
IsNothing is only used in VB or VB.NET. someone is really confused
Login to rate this answer.
Check if (dataset != null), and then work on dataset.
Login to rate this answer.
Here it is folks:
- You need to firstly check to see if the dataset actually exists
- Then check if it has one or more tables
- Then check the row count for each table to see if any one table has data
Example.
System.Data.DataSet data = new System.Data.DataSet();
//data = bla bla get some data;
bool dataFound = false;
if( data != null && data.Tables.Count > 0 && data.Tables[ 0 ].Rows.Count > 0 )
{
foreach( System.Data.DataTable table in data.Tables )
{
if( table.Rows.Count > 0 )
{
//we have data
dataFound = true;
break;
}
}
}
if( dataFound )
{
Console.WriteLine( "we have data" );
}
else
{
Console.WriteLine( "we have NO data" );
}
Login to rate this answer.
Anais
Answered On : May 31st, 2012
Thank you Seeker911, your answer helped me :)
Login to rate this answer.
Rajavel
Answered On : Nov 19th, 2012
Code
if(dataset.Tables.count!=0)
{
do some operation
}
else
{
nothing...
}
Login to rate this answer.