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?


 
HojoformoAsked:
Who is Participating?
 
Pra4444Connect With a Mentor Commented:
can  you not try
select count(*) from ...whatever query you are using..

if count is zero then you know its null and just dont proceed from there..

you can also set datatable's visible property to false...
you can catch nullexception and do something there??
0
 
YZlatCommented:
did you declare your datatable or dataset with keyword New?

Like

dim ds as new dataset

or

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

can you post some code?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.