Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

SqlParameter.Scale Property

Gets or sets the number of decimal places to which Value is resolved.

Namespace:  System.Data.SqlClient
Assembly:  System.Data (in System.Data.dll)
public byte Scale { get; set; }

Property Value

Type: System.Byte
The number of decimal places to which Value is resolved. The default is 0.

Implements

IDbDataParameter.Scale

The Scale property is used by parameters that have a SqlDbType of Decimal.

Caution noteCaution

Data may be truncated if the Scale property is not explicitly specified and the data on the server does not fit in scale 0 (the default).

You do not need to specify values for the Precision and Scale properties for input parameters, as they can be inferred from the parameter value. Precision and Scale are required for output parameters and for scenarios where you need to specify complete metadata for a parameter without indicating a value, such as specifying a null value with a specific precision and scale.

NoteNote

Use of this property to coerce data passed to the database is not supported. To round, truncate, or otherwise coerce data before passing it to the database, use the Math class that is part of the System namespace prior to assigning a value to the parameter's Value property.

NoteNote

.NET Framework data providers that are included with the .NET Framework version 1.0 do not verify the Precision or Scale of Decimal parameter values. This can cause truncated data to be inserted at the data source. If you are using .NET Framework version 1.0, validate the Precision and SqlParameter of Decimal values before setting the parameter value. Scale values that exceed the Decimal parameter scale are still truncated.

The following example creates a SqlParameter and sets some of its properties.


static void CreateSqlParameterPrecisionScale()
{
    SqlParameter parameter = new SqlParameter("Price", SqlDbType.Decimal);
    parameter.Value = 3.1416;
    parameter.Precision = 8;
    parameter.Scale = 4;
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.