?
Solved

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

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
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…
Suggested Courses

765 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