I have the object not set to a reference problem (null exception) problem with SafeDataREader
Its concept wise contradicting. The very purpose of using SafeDataReader is to avoid excess code checking for null exceptions. its the problem with Module.ParentId in datafetch method. This could be null in the DB..
I think I know what the problem is, is it because we are initializing new objects in getList, but this is the way, I have it working in all my other BO objects and list...
Any help appreciated..
Thanks,
RSB
In ModuleList.cs
private
void Fetch(SafeDataReader dr){
In Module.cs
internal
static BOModules GetAllModules(SafeDataReader dr){
}
private void DataPortal_Fetch(SafeDataReader dr){BModuleID = dr.GetValue(
"MODULEID").ToString();BModuleName = dr.GetString(
"MODULENAME");BModuleDesc = dr.GetString(
"MODULEDESC");BModuleDisplay = dr.GetValue(
"MODULEDISPLAY").ToString(); //if (dr.GetValue("MODULEPARENTID") != null)BModuleParentID = dr.GetValue(
"MODULEPARENTID").ToString(); //else //BModuleParentID = String.Empty;MarkOld();
}
I have a custom data access class which retrieves the list of modules from DB. The code is as follows
private
void GetGroupModules(string pGroupID){
DataAccessLayer dl = new DataAccessLayer();dl.DbCommand = "GETGROUPMODULES";
try{
dl.AddParameter(
"poReturn_code", DbTypes.INT);dl.AddParameter(
"cur_OUT", DbTypes.REFCURSOR);dl.AddParameter(
"pGROUPID", pGroupID); using (SafeDataReader dr = new SafeDataReader(dl.ExecuteReader())){
Fetch(dr);
}
dl.Close();
}
catch (System.Exception ex){
throw new System.Security.SecurityException("Error in BOModulesList.GetGroupModules(string pGroupID): " + ex);}
Thanks,
RSB
RSB:I have the object not set to a reference problem (null exception) problem with SafeDataREader
What object is null?
Are you saying that GetValue() is sometimes returning null? That is the intended behavior of GetValue() in the case that the database value is DBNull. It has to be this way, because GetValue() returns type object, and the "default" value of object is null.
If you want to avoid getting a null, call GetInt32() or one of the other strongly typed methods.
Thank you!! This worked!!
RSB
Copyright (c) Marimer LLC