Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Handling DB Nulls
Message
From
28/12/2009 11:06:37
 
General information
Forum:
ASP.NET
Category:
Class design
Miscellaneous
Thread ID:
01440804
Message ID:
01440861
Views:
51
Kevin,

I'm sure I've posted my GetNonNull set of static methods here a gazillion times. <g> Here it is again in the form of a link to my blog post about it:

http://geek-goddess-bonnie.blogspot.com/2009/11/getting-non-null-data.html

~~Bonnie




>I'm reading the values off a dataset onto class properties:
>
>
>public override void LoadData()
>{
>    DataSet ds = AppDataAccess.GetProjects(this.RecordId);
>
>    if (ds != null && ds.Tables.Count > 0)
>    {
>        _ProjectKey = (int)ds.Tables[0].Rows[0]["ProjectKey"];
>        _ClientKey = (int)ds.Tables[0].Rows[0]["ClientKey"];
>        _ProjectTypeKey = (int)ds.Tables[0].Rows[0]["ProjectTypeKey"];
>        _RateTypeKey = (int)ds.Tables[0].Rows[0]["RateTypeKey"];
>        _ProjectStatusKey = (int)ds.Tables[0].Rows[0]["ProjectStatusKey"];
>        _PriorityKey = (int)ds.Tables[0].Rows[0]["PriorityKey"];
>
>        if (ds.Tables[0].Rows[0]["ManagerKey"] != DBNull.Value)
>        {
>            _ManagerKey = (int)ds.Tables[0].Rows[0]["ManagerKey"];
>        }
>
>        _ProjectName = ds.Tables[0].Rows[0]["ProjectName"].ToString();
>        _ProjectCode = ds.Tables[0].Rows[0]["ProjectCode"].ToString();
>        _RateAmt = (float)ds.Tables[0].Rows[0]["RateAmt"];
>        _EstHours = (float)ds.Tables[0].Rows[0]["EstHours"];
>        _TotalHours = (float)ds.Tables[0].Rows[0]["TotalHours"];
>        _EstStartDate = (DateTime)ds.Tables[0].Rows[0]["EstStartDate"];
>        _EstEndDate = (DateTime)ds.Tables[0].Rows[0]["EstEndDate"];
>        _ActualStartDate = (DateTime)ds.Tables[0].Rows[0]["ActualStartDate"];
>        _ActualEndDate = (DateTime)ds.Tables[0].Rows[0]["ActualEndDate"];
>        _PercentDone = (float)ds.Tables[0].Rows[0]["PercentDone"];
>        _Comments = ds.Tables[0].Rows[0]["Comments"].ToString();
>        _ProjectType = ds.Tables[0].Rows[0]["ProjectType"].ToString();
>        _RateType = ds.Tables[0].Rows[0]["RateType"].ToString();
>        _Status = ds.Tables[0].Rows[0]["Status"].ToString();
>        _Priority = ds.Tables[0].Rows[0]["Priority"].ToString();
>        _MgrFirstName = ds.Tables[0].Rows[0]["MgrFirstName"].ToString();
>        _MgrLastName = ds.Tables[0].Rows[0]["MgrLastName"].ToString();
>
>    }
>}
>
>
>The problem is that I'm getting casting errors when there are DB nulls., Is there a better way of dealing with this other than the IF statement I used above? I don't want a bunch of IF's around each line above.
>
>Thanks
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform