Check for the existance of a specific table in a dataset.

U

UJ

I'm getting a dataset back from a web service and I want to verify that the
table I want exists before trying to access it (which will cause an
exception.) Is there an easy way to check for a specific table in my dataset
without doing a try/catch or is that the easiest way?

TIA - Jeff.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

UJ said:
I'm getting a dataset back from a web service and I want to verify that
the table I want exists before trying to access it (which will cause an
exception.) Is there an easy way to check for a specific table in my
dataset without doing a try/catch or is that the easiest way?

if ( dataSet.Tables["MyTable"] == null )
throw new exception("Table no present");

in other words, just check for null when you refer to the table, the same
apply to columns
 
R

Randal

You can do what Ignacio says or there is also a "Contains" attribute
from the table and column collections to verify the existence of a
member before accessing it.

_Randal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top