Solved

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

Posted on 2006-10-20
5
267 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?


 
0
Comment
Question by:Hojoformo
  • 2
  • 2
5 Comments
 
LVL 12

Accepted Solution

by:
Pra4444 earned 500 total points
ID: 17776522
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
 
LVL 35

Expert Comment

by:YZlat
ID: 17776672
did you declare your datatable or dataset with keyword New?

Like

dim ds as new dataset

or

dim ds as new datatable?
0
 

Author Comment

by:Hojoformo
ID: 17776782
it was defined with a a new dataset, why?  
0
 

Author Comment

by:Hojoformo
ID: 17776817
it was defined like DataSet ds = new DataSet();
0
 
LVL 35

Expert Comment

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

can you post some code?
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now