Solved

How to check if dataset tables exist in VS 2005 C#?

Posted on 2008-06-24
3
1,789 Views
Last Modified: 2013-11-26
I have a stored procedure in which I have about 4 select statements which means I have 4 tables. I am populating 4 dropdown controls with these tables in the prerender event. If one or more of the tables does not return any rows, I get an error saying Table[0] does not exist. How can I check if all the tables in the dataset exist?
0
Comment
Question by:haritha_204
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 8

Expert Comment

by:Chumad
ID: 21858120
I suspect there is a count property - DataTable.Tables.Count - you could always check that to make sure it returns a count higher than the table index you are trying to read.

So... if Count is 0, then Table[0] is going to return an error because it doesn't exist.
0
 
LVL 2

Accepted Solution

by:
larker1 earned 125 total points
ID: 21858148
You should be able to simply check the myDS.Tables.Count property, which returns an int of the number of tables in the dataset.
Alternately, you could use the myDS.Tables.Contains("myTableName") which returns a bool.  
0
 

Author Closing Comment

by:haritha_204
ID: 31470231
Thanks for the quick responses Chumad and larker1. My issue is resolved
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

742 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