Home All Groups Group Topic Archive Search About

protect overflow of sql data type decimal(9,3)

Author
29 Jan 2005 2:46 AM
Zeng
Hello,

I have many fields in my SQL database that are of type decimal(9,3).  How do
I detect a decimal value (type decimal in C#) will overflow the db column of
sql type decimal (9,3)?   Is there a way to figure out the min/max constants
of decimal(9,3) to compare against in C# to make sure the new value is "in
bound"?

Thanks!
-zeng
Author
29 Jan 2005 4:43 PM
Dan Guzman
If you know that the SqlDecimal precision is 9 and the scale is 3, you can
simply do a range validation like the example below.

private bool IsInBound(decimal DecimalValue)
{
    if((DecimalValue > 999999.999m) || (DecimalValue < -999999.999m))
        return false;
    return true;
}


--
Hope this helps.

Dan Guzman
SQL Server MVP

Show quoteHide quote
"Zeng" <Zeng5***@hotmail.com> wrote in message
news:uPmNC0aBFHA.1452@TK2MSFTNGP11.phx.gbl...
> Hello,
>
> I have many fields in my SQL database that are of type decimal(9,3).  How
> do
> I detect a decimal value (type decimal in C#) will overflow the db column
> of
> sql type decimal (9,3)?   Is there a way to figure out the min/max
> constants
> of decimal(9,3) to compare against in C# to make sure the new value is "in
> bound"?
>
> Thanks!
> -zeng
>
>

Bookmark and Share