Solved

best way to check if a datatable is empty

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

828 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