Solved

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

Posted on 2008-06-24
3
1,786 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
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

785 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