.NET Framework Class Library
SqlParameter..::.Value Property

Gets or sets the value of the parameter.

Namespace:  System.Data.SqlClient
Assembly:  System.Data (in System.Data.dll)
Syntax

Visual Basic (Declaration)
<TypeConverterAttribute(GetType(StringConverter))> _
Public Overrides Property Value As Object
Visual Basic (Usage)
Dim instance As SqlParameter
Dim value As Object

value = instance.Value

instance.Value = value
C#
[TypeConverterAttribute(typeof(StringConverter))]
public override Object Value { get; set; }
Visual C++
[TypeConverterAttribute(typeof(StringConverter))]
public:
virtual property Object^ Value {
    Object^ get () override;
    void set (Object^ value) override;
}
JScript
public override function get Value () : Object
public override function set Value (value : Object)

Property Value

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

Implements

IDataParameter..::.Value
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 you send 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.

An exception is thrown if non-Unicode XML data is passed as a string.

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

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

The Value property is overwritten by SqlDataAdapter.UpdateCommand.

Examples

The following example creates a SqlParameter and sets some of its properties.

Visual Basic
Private Sub CreateSqlParameterVersion()
    Dim parameter As New SqlParameter("Description", SqlDbType.VarChar, 88)
    parameter.Value = "garden hose"
End Sub
C#
static void CreateSqlParameterVersion()
{
    SqlParameter parameter = new SqlParameter("Description", SqlDbType.VarChar, 88);
    parameter.Value = "garden hose";
}
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0
See Also

Reference

Other Resources

Tags :


Page view tracker