OleDbParameter.Scale 属性

定义

获取或设置所解析的 Value 的小数位数。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

属性值

Byte

Value 进行解析的小数位数。The number of decimal places to which Value is resolved. 默认值为 0。The default is 0.

实现

属性

示例

下面的示例创建 OleDbParameter 并设置其一些属性。The following example creates an OleDbParameter and sets some of its properties.

Public Sub CreateOleDbParameter()  
    Dim parameter As New OleDbParameter("Price", OleDbType.Decimal)  
    parameter.Value = 3.1416  
    parameter.Precision = 8  
    parameter.Scale = 4  
End Sub 'CreateOleDbParameter  
public void CreateOleDbParameter()   
 {  
    OleDbParameter parameter = new OleDbParameter("Price", OleDbType.Decimal);  
    parameter.Value = 3.1416;  
    parameter.Precision = 8;  
    parameter.Scale = 4;  
 }  

注解

Scale 调用 Prepare 的方法 OleDbCommand 并指定数值输出参数之前,属性仅用于 decimal 和数值输入参数。The Scale property is only used for decimal and numeric input parameters before calling the Prepare method of the OleDbCommand and to specify numeric output parameters.

如果将此属性设置为数据库中的值以外的值,则将取决于数据访问接口的实现,并且可能会返回错误代码、截断或舍入数据。Setting this property to a value other than the value in the database depends on the implementation of the data provider and may return an error code, truncate, or round data.

当使用 SQL Server Native Client 10 (或更高版本的) 时,若要绑定类型为、、、或的参数, Decimal Numeric VarNumeric DBDate DBTimeStamp 则必须手动指定适当的缩放值。When using SQL Server Native Client 10 (or later), to bind a parameter whose type is Decimal, Numeric, VarNumeric, DBDate, or DBTimeStamp, you must manually specify an appropriate scale value.

备注

不支持使用此属性来强制传递到数据库的数据。Use of this property to coerce data passed to the database is not supported. 若要在将数据传递到数据库之前对其进行舍入、截断或强制转换,请使用命名空间中的类,然后将 Math System 值分配给该参数的 Value 属性。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.

备注

.NET Framework 版本1.0 附带 .NET Framework 数据提供程序不验证 Precision Scale Decimal 参数值的或。.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. 如果使用 .NET Framework 版本1.0,请 Precision OleDbParameter Decimal 在设置参数值之前验证和值。If you are using .NET Framework version 1.0, validate the Precision and OleDbParameter of Decimal values before setting the parameter value. Scale 超出 Decimal 参数范围的值仍会被截断。Scale values that exceed the Decimal parameter scale are still truncated.

适用于