Link to home
Start Free TrialLog in
Avatar of Hojoformo
Hojoformo

asked on

Datatable null - not set to an instance of an object - best approach for handling

What is the best way to program for a null table.  I have a C# program that calls a class to fill a DataTable named DS based on a condition.  It is possible the datatable will return null from the call and the program crashes with "Object Not Set to an Instance of An Object".  What is the best way to handle this conidtion?  Should I add a dummy row to the table if the condition is not before returning?  or is there a command that will set this object object a null instance?


 
ASKER CERTIFIED SOLUTION
Avatar of Pra4444
Pra4444
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of YZlat
did you declare your datatable or dataset with keyword New?

Like

dim ds as new dataset

or

dim ds as new datatable?
Avatar of Hojoformo
Hojoformo

ASKER

it was defined with a a new dataset, why?  
it was defined like DataSet ds = new DataSet();
because if ther is not data and dataset is defined witout keyword New, you will get an error.

can you post some code?