I'm using C# to run a couple stored procedures and return in dataset. I've been using:

if(dset.Tables.Count > 0)
{
  for(int i = 0; i < dset.Tables[0].Rows.Count; i++)
  {
    //some code
  }

}

is there a shorter way to do this without the if statement?

Recommended Answers

All 2 Replies

Hello,
Yes, this is good way. Try one more if you like:

foreach (DataTable table in dataset.Tables)
            {
               //some code
            }

Sorry...

foreach (DataTable table in dataset.Tables)
            {
                if (table.Rows.Count > 0)
                {
                    //some code
                }
            }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.