Solved

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

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

838 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