?
Solved

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

Posted on 2006-10-20
5
Medium Priority
?
288 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 12

Accepted Solution

by:
Pra4444 earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

770 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