Sunday, April 15, 2012

DataSet HasTables Method

DataSet Extentions.
Add Methods to Objects.

So, it's getting me tired to always right:
     if (ds != null && ds.Tables.Count > 0)
to make sure that a certain dataset really has tables inside.

So here is an extension I added to the DataSet object:
        public static bool HasTables(this DataSet ds)
        {
            if (ds != null && ds.Tables.Count > 0)
                return true;
 
            return false;
        }

Simple, yet efficient :)

Elad Shalom,
CTO at ITweetLive.com

3 comments: