OdbcParameter.Value 属性

定义

获取或设置参数的值。Gets or sets the value of the parameter.

public:
 property System::Object ^ Value { System::Object ^ get(); void set(System::Object ^ value); };
[System.ComponentModel.TypeConverter(typeof(System.ComponentModel.StringConverter))]
public object Value { get; set; }
member this.Value : obj with get, set
Public Property Value As Object

属性值

充当参数值的 ObjectAn Object that is the value of the parameter. 默认值为 null。The default value is null.

实现

属性

示例

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

Public Sub CreateOdbcParameter()  
    Dim parameter As New OdbcParameter("Description", OdbcType.VarChar, 88)  
    parameter.Value = "garden hose"  
End Sub   
public void CreateOdbcParameter()   
 {  
    OdbcParameter parameter = new OdbcParameter("Description", OdbcType.VarChar, 88);  
    parameter.Value = "garden hose";  
 }  

注解

对于输入参数,值将绑定到发送到服务器的 OdbcCommandFor input parameters, the value is bound to the OdbcCommand that is sent to the server. 对于输出和返回值参数,值将在 OdbcCommand 完成时和 OdbcDataReader 关闭后设置。For output and return-value parameters, the value is set on completion of the OdbcCommand and after the OdbcDataReader is closed.

向服务器发送空参数值时,用户必须指定 DBNull,而不是 null。When you send a null parameter value to the server, the user must specify DBNull, not null. 系统中的 null 值是没有值的空对象。A null value in the system is an empty object that has no value. DBNull 用于表示 NULL 值。DBNull is used to represent null values. 如果使用参数调用带有具有默认值的参数的存储过程,则将 Value 设置为 null 会导致使用默认值。If the parameter is used to call a stored procedure with parameters that have default values, setting Value to null causes the default value to be used.

如果应用程序指定了数据库类型,则当提供程序将数据发送到服务器时,绑定值将转换为该类型。If the application specifies the database type, the bound value is converted to that type when the provider sends the data to the server. 如果提供程序支持 IConvertible 接口,则会尝试转换任何类型的值。The provider tries to convert any type of value if it supports the IConvertible interface. 如果指定的类型与值不兼容,则可能会导致转换错误。Conversion errors may result if the specified type is not compatible with the value.

DbTypeOdbcType 属性都可以通过设置 Value来推断。Both the DbType and OdbcType properties can be inferred by setting Value. 如果适用,则在执行参数化语句时,还会从 Value 中推断大小、精度和小数位数。If applicable, the size, precision, and scale is also inferred from Value when the parameterized statement is executed. 但是,不向用户公开推断值。However, inferred values are not exposed to the user.

Update 方法将覆盖 Value 属性。The Value property is overwritten by the Update method.

适用于

另请参阅