Solved

best way to check if a datatable is empty

Posted on 2011-09-12
1
205 Views
Last Modified: 2012-05-12
I have a datatable that is part of a class definition.
I will be querying the database the first time this variable is accessed in a private method.

private DataTable _lookup = new DataTable();

What is the best way to do it?

I currently use

_postlablookup.Rows.Count == 0

But it feels like there must be something better. Could I just check for null?

What are the pros and cons of each method?
0
Comment
Question by:olmuser
1 Comment
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 125 total points
ID: 36526302
You should really be checking for both:

if (_lookup != null && _lookup.Rows.Count > 0)
{
    // code
}

Open in new window

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

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

932 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

14 Experts available now in Live!

Get 1:1 Help Now