Searching DataSet for a specific Table

 

private Boolean tableExists(string name)

{

Boolean success = false;

int rows = ReportDS.Tables[name].Rows.Count;

if (rows > 1)

success = true;

return success;

}

 

I'm using this code to determine if the datatable exists. When it hits ReportDS.Tables[name].Rows.Count; it throws an exception for Object Reference not set to an Instance of an object. The ReportDS is declared as

DataSet ReportDS = new DataSet();

 

above the tableExists declaration (global to the class)

 

Is there a better way accomplish what I'm trying to do I looked for a table.exists property, but have found nothing that seems to pertain to what I'm trying to do. Help would be appreciated.



Answer this question

Searching DataSet for a specific Table

  • preethi_rjs

    Modified the above code to be

    ...

    {

    Boolean success = false;

    if( ReportDS.Tables.Contains(name) )

    success = true;

    return success;

    }

    Amazing how quickly the answer comes ... after you've asked the question.


  • Searching DataSet for a specific Table