Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
X002548
Not Just a Number
15586 Posts |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-10-22 : 16:34:20
|
usually this is handled in the get property.of course there can be oter variationspublic decimal MyProperty{ get { if (dr["MyProperty"] == null) return 0 return (decimal)dr["MyProperty"] } } _______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2007-10-22 : 16:47:47
|
Am I being smoked?Actually used this code: decimal dADLeaseHold = 0; decimal dADComm = 0; decimal dADFurn = 0; if (mepExpenseSummary.ADLeaseHold.HasValue) { dADLeaseHold = (decimal)mepExpenseSummary.ADLeaseHold; } if (mepExpenseSummary.ADComm.HasValue) { dADComm = (decimal)mepExpenseSummary.ADComm; } if (mepExpenseSummary.ADFurn.HasValue) { dADFurn = (decimal)mepExpenseSummary.ADFurn; } decimal aggregate = (decimal)mepExpenseRep.continuedad + (decimal)mepExpenseRep.sum_annualoccupancy + (decimal)mepExpenseSummary.CapExpensedItems + dADLeaseHold + dADComm + dADFurn;We check for null in many-many places, but probably not in all. Some derived fields will always have values and it is handled in sproc, etc. Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-10-22 : 17:11:25
|
emm... huh?? you check for nulls in many many places???null conversion is done only in one place: the DB Layer.you set the business rule of what you want null to represent for each datatype and you convert it there.datetime is the perfect exampleif DateTime.MinValue is meant to be null then you use that in the DAL.and vice versa when you get DateTime.MinValue back to the DAL you convert it to null.of course maybe your busines requirements need these checks in many many places... but i doubt it._______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-10-23 : 02:07:29
|
Is there not ISNULL function in ASP.NET?In VB6,IIF(ISNULL(dec)="true",0,dec)MadhivananFailing to plan is Planning to fail |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-10-23 : 03:45:27
|
"How do you handle null?"I have functions (inspired by something some Microsoftie wrote - Code Complete, or one of those titles) called "Safe".So StringToNumberSafe(SomeString) will never fail, and will return a "safe" value. This avoids embarrassing application errors, and an empty string can probably safely be converted to zero. NULL to in all probability. And a non-numeric-string. The Function can log "unexpected" values, so that developers can know that there are duff values "in the wild" (and in Dev Mode they can fail with suitable error message so that inaccurate code is cleaned up.In all probability I would have optional parameters for return values for non-number, empty, NULL, whatever. Then the application can choose to have, say, -1 returned for unexpected values.Kristen |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2007-10-23 : 10:07:20
|
another common way to handle null in C# is to use Nullable<T>. it basically wraps value types in an object with some useful properties like HasValue and Value. elsasoft.org |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|
|
|