Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-06-24
3
Medium Priority
?
1,792 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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

609 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