Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

948 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

22 Experts available now in Live!

Get 1:1 Help Now