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

  • Thread starter Thread starter UJ
  • Start date Start date
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.
 
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
 
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
 
Back
Top