How to check if table is empty

G

Guest

I am currenlty using the following code to check if the table is empty. I
wonder if there is a more elegant way of doing this:

private bool IsEmptyTable()
{
int RecordCount;
DataTable customersTable = CustomerDB.GetCustomers();
RecordCount = customersTable.Rows.Count;
if (RecordCount != 0)
isEmpty = false;
else
isEmpty = true;
return isEmpty;
}

Thanks
 
P

perspolis

cm=(CurrencyManager)this.BindingContext[customersTable,""];
if(cm.Count>0) // or if(cm.Position>=0)
IsEmpty=false;
else
IsEmpty=true;
 
C

Cor Ligthert

Hodari,

Although not the best in academical question do you mean with table is empty
Is not instanced
(MyDataTable ==null)

Has by instance no rows?
(MyDataTable.Rows.Count == 0);

I hope this helps somehow.

Cor
 

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

Top