Export (0) Print
Expand All

SqlParameter.Value Property

Gets or sets the value of the parameter.

[Visual Basic]
Public Overridable Property Value As Object  Implements _
   IDataParameter.Value
[C#]
public virtual object Value {get; set;}
[C++]
public: __property virtual Object* get_Value();
public: __property virtual void set_Value(Object*);
[JScript]
public function get Value() : Object;
public function set Value(Object);

Property Value

An Object that is the value of the parameter. The default value is null.

Implements

IDataParameter.Value

Remarks

For input parameters, the value is bound to the SqlCommand that is sent to the server. For output and return value parameters, the value is set on completion of the SqlCommand and after the SqlDataReader is closed.

When sending a null parameter value to the server, the user must specify DBNull, not null. The null value in the system is an empty object that has no value. DBNull is used to represent null values.

If the application specifies the database type, the bound value is converted to that type when the provider sends the data to the server. The provider attempts 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.

Both the SqlDbType and DbType properties can be inferred by setting the Value.

The Value property is overwritten by Update.

Example

[Visual Basic, C#, C++] The following example creates a SqlParameter and sets some of its properties.

[Visual Basic] 
Public Sub CreateSqlParameter()
    Dim myParameter As New SqlParameter("@Description", SqlDbType.VarChar)
    myParameter.Value = "garden hose"
    myParameter.Size = 11
End Sub 'CreateSqlParameter

[C#] 
public void CreateSqlParameter() 
 {
    SqlParameter myParameter = new SqlParameter("@Description", SqlDbType.VarChar);
    myParameter.Value = "garden hose";
    myParameter.Size = 11;
 }

[C++] 
public:
void CreateSqlParameter() 
 {
    SqlParameter* myParameter = new SqlParameter(S"@Description", SqlDbType::VarChar);
    myParameter->Value = S"garden hose";
    myParameter->Size = 11;
 }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

SqlParameter Class | SqlParameter Members | System.Data.SqlClient Namespace | SqlDbType | DbType

Show:
© 2014 Microsoft