We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

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

Hojoformo
Hojoformo asked
on
Medium Priority
307 Views
Last Modified: 2008-03-03
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?


 
Comment
Watch Question

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??

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
CERTIFIED EXPERT

Commented:
did you declare your datatable or dataset with keyword New?

Like

dim ds as new dataset

or

dim ds as new datatable?

Author

Commented:
it was defined with a a new dataset, why?  

Author

Commented:
it was defined like DataSet ds = new DataSet();
CERTIFIED EXPERT

Commented:
because if ther is not data and dataset is defined witout keyword New, you will get an error.

can you post some code?
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.