Dataset - determine if no records are returned

G

Guest

Hello -

I have a button that when clicked displays a dataset in a datagrid. I need
code to simply display a label instead of the datagrid if no rows are
returned.

Is there a simple way to put this in an If statement or do I have to
establish another connection and use Count to be able to determine if no rows
are returned?

Any help will be greatly appreciated!
 
M

Mark Rae

I have a button that when clicked displays a dataset in a datagrid. I
need
code to simply display a label instead of the datagrid if no rows are
returned.

Is there a simple way to put this in an If statement or do I have to
establish another connection and use Count to be able to determine if no
rows
are returned?

Datasets contain at least one Table, which has a Rows.Count property. If
your Dataset contains just one table, you might do something like (in C#)

if(objDS.Tables[0].Rows.Count > 0)
{
// bind to the datagrid
}
else
{
// do something else
}

However, if all you need the Dataset for is to bind it to a datagrid, you
might find that a DataReader is much more efficient. In v1.1 DataReader
objects have a Boolean HasRows property.
 
G

Guest

Thanks, Mark!

Mark Rae said:
I have a button that when clicked displays a dataset in a datagrid. I
need
code to simply display a label instead of the datagrid if no rows are
returned.

Is there a simple way to put this in an If statement or do I have to
establish another connection and use Count to be able to determine if no
rows
are returned?

Datasets contain at least one Table, which has a Rows.Count property. If
your Dataset contains just one table, you might do something like (in C#)

if(objDS.Tables[0].Rows.Count > 0)
{
// bind to the datagrid
}
else
{
// do something else
}

However, if all you need the Dataset for is to bind it to a datagrid, you
might find that a DataReader is much more efficient. In v1.1 DataReader
objects have a Boolean HasRows property.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top