Link to home
Start Free TrialLog in
Avatar of quest_capital
quest_capital

asked on

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

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

Avatar of Sathish DV
Sathish DV
Flag of United States of America image

hi,
can u add code for Get_WO(field, uid, DAL_Core.filter). Need to see any thing is missing from initialization?
Avatar of Andrew Crofts
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
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.
Try this:
 
if(ds != null && ds.Tables != null)
     int dscount = ds.Tables.Count;

Open in new window


Hope it helps.
Boccio
ASKER CERTIFIED SOLUTION
Avatar of quest_capital
quest_capital

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of quest_capital
quest_capital

ASKER

I found the problem.