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.NullReferenceExcept ion: 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
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.NullReferenceExcept
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
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
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:
Hope it helps.
Boccio
if(ds != null && ds.Tables != null)
int dscount = ds.Tables.Count;
Hope it helps.
Boccio
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I found the problem.
can u add code for Get_WO(field, uid, DAL_Core.filter). Need to see any thing is missing from initialization?