Editar

Compartir a través de


SqlParameter.Scale Property

Definition

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

public:
 property System::Byte Scale { System::Byte get(); void set(System::Byte value); };
public byte Scale { get; set; }
[System.Data.DataSysDescription("DbDataParameter_Scale")]
public byte Scale { get; set; }
member this.Scale : byte with get, set
[<System.Data.DataSysDescription("DbDataParameter_Scale")>]
member this.Scale : byte with get, set
Public Property Scale As Byte

Property Value

The number of decimal places to which Value is resolved. The default is 0.

Implements

Attributes

Examples

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;
}
Private Sub CreateSqlParameterPrecisionScale()
    Dim parameter As New SqlParameter("Price", SqlDbType.Decimal)
    parameter.Value = 3.1416
    parameter.Precision = 8
    parameter.Scale = 4
End Sub

Remarks

The Scale property is used by parameters that have a SqlDbType of Decimal, DateTime2, DateTimeOffset, or Time.

Warning

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). For the DateTime2 type, scale 0 (the default) will be passed as datetime2(7). There is currently no way to send a parameter as datetime2(0). Scales 1-7 work as expected. This problem applies to DateTimeOffset and Time as well.

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.

Note

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.

Note

.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.

Applies to

See also