OdbcParameter.Scale 属性


获取或设置所解析的 Value 的小数位数。Gets or sets the number of decimal places to which Value is resolved.

 property System::Byte Scale { System::Byte get(); void set(System::Byte value); };
public byte Scale { get; set; }
member this.Scale : byte with get, set
Public Property Scale As Byte


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



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

Public Sub CreateOdbcParameter()  
    Dim parameter As New OdbcParameter("Price", OdbcType.Decimal)  
    parameter.Value = 3.1416  
    parameter.Precision = 8  
    parameter.Scale = 4  
End Sub   
public void CreateOdbcParameter()   
    OdbcParameter parameter = new OdbcParameter("Price", OdbcType.Decimal);  
    parameter.Value = 3.1416;  
    parameter.Precision = 8;  
    parameter.Scale = 4;  


Scale 属性仅用于 decimal 和数值输入参数。The Scale property is used only for decimal and numeric input parameters.

将此属性设置为数据库中的值以外的值的效果取决于数据访问接口的实现,并且可能会返回错误代码,或者截断或舍入数据。The effect of 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, or truncate or round data.

Scale 属性仅影响其 OdbcTypeDecimalNumeric的参数。The Scale property only affects parameters whose OdbcType is Decimal or Numeric. 对于其他数据类型,将忽略 ScaleFor other data types, Scale is ignored.

使用 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. 若要在将数据传递到数据库之前对其进行舍入、截断或强制转换,请先使用 System 命名空间的一部分 Math 类,然后再为参数的 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 数据提供程序不验证 Decimal 参数值的 scale.NET Framework data providers that are included with the .NET Framework version 1.0 do not verify the scale of Decimal parameter values. 这可能会导致在数据源中插入修改后的数据。This can cause modified data being inserted at the data source. 如果使用 .NET Framework 版本1.0,请在设置参数值之前验证 decimal 值的 scaleIf you are using .NET Framework version 1.0, validate the scale of decimal values before setting the parameter value. 当你使用 .NET Framework 版本1.1 或更高版本时,如果这是基础 ODBC 驱动程序的行为,则超出 decimal 参数范围的 scale 值可能仅会被截断。When you use .NET Framework version 1.1 or later versions, scale values that exceed the decimal parameter scale might only be truncated in scale, if that is the behavior of the underlying ODBC driver.