C#: Check a Dataset for Results

I’ve been mostly using nHibernate lately when working in .NET. Sometimes I get thrown on an old web forms project and forget how to do some simple things. In this case I had DataSet and needed to check it for data before proceeding. This is all you need to do:

if (dataSet.Tables[0].Rows.Count < 0) {

In my case I had actually made a simple pagination system. I needed to know if the DataSet had more than 20 results - otherwise I'd hide the "more" link.

if (dataSet.Tables[0].Rows.Count <= 20)
    olderNews.Visible = false;
    olderNews.Attributes["href"] = "?offset=" + (Int32.Parse(offset) + 20);

Nothing special but I hope it helps!

Creating your first programming language is easier than you think.

Understanding how a programming language works is a surefire way to be a better developer. Read more.

Suggested Reading

written by Ryan Bosinger
Ryan is a web developer living and working in Banff Alberta. He also writes for giftsforpeoplewitheverything.com and freefoley.com.

Leave a Reply