Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

C# Object reference not set to an instance of an object.

Posted on 2011-05-11
6
Medium Priority
?
317 Views
Last Modified: 2012-05-11
I have a page that seems to be coded properly, however every now and than I get the error below.
That is wrong with line 66 I don't get it.

------------------------------------------------------------------------------------------
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 64:         BAL_Core cor = new BAL_Core();
Line 65:         DataSet ds = cor.Get_WO(field, uid, DAL_Core.filter);
Line 66:         int dscount = ds.Tables.Count;
Line 67:         if (dscount > 0)
Line 68:         {
 

Source File: d:\wwwroot\MOC2\wo.aspx.cs    Line: 66

0
Comment
Question by:quest_capital
6 Comments
 
LVL 4

Expert Comment

by:Sathish DV
ID: 35737843
hi,
can u add code for Get_WO(field, uid, DAL_Core.filter). Need to see any thing is missing from initialization?
0
 
LVL 13

Expert Comment

by:Philip Pinnell
ID: 35737859
If there is a problem with line 65, ie cor.Get_WO doesn't actually return a dataset line 66 will give the error you report.

You should look at why a ds might not be returned.

You could test ds to see if it is null/nothing before trying to use it
0
 
LVL 9

Expert Comment

by:gery128
ID: 35738166
Check if you are passing valid values to BAL function Get_WO and if its returning proper dataset by filling it with data. Your dataset seems to be null.
0
Technology Partners: 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!

 
LVL 3

Expert Comment

by:tbsolutions
ID: 35738429
Try this:
 
if(ds != null && ds.Tables != null)
     int dscount = ds.Tables.Count;

Open in new window


Hope it helps.
Boccio
0
 

Accepted Solution

by:
quest_capital earned 0 total points
ID: 36109071
I needed to use the Try,Catch & Finally method to open an close my db connections.
0
 

Author Closing Comment

by:quest_capital
ID: 36128946
I found the problem.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

580 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