Solved

best way to check if a datatable is empty

Posted on 2011-09-12
1
204 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 74

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

19 Experts available now in Live!

Get 1:1 Help Now