Export (0) Print
Expand All

SqlParameter Constructor (String, Object)

Initializes a new instance of the SqlParameter class that uses the parameter name and a value of the new SqlParameter.

Namespace: System.Data.SqlClient
Assembly: System.Data (in system.data.dll)

'Declaration
Public Sub New ( _
	parameterName As String, _
	value As Object _
)
'Usage
Dim parameterName As String
Dim value As Object

Dim instance As New SqlParameter(parameterName, value)
public SqlParameter (
	String parameterName, 
	Object value
)
public function SqlParameter (
	parameterName : String, 
	value : Object
)

Parameters

parameterName

The name of the parameter to map.

value

An Object that is the value of the SqlParameter.

When you specify an Object in the value parameter, the SqlDbType is inferred from the Microsoft .NET Framework type of the Object.

Use caution when you use this overload of the SqlParameter constructor to specify integer parameter values. Because this overload takes a value of type Object, you must convert the integral value to an Object type when the value is zero, as the following C# example demonstrates.

Parameter = new SqlParameter("@pname", Convert.ToInt32(0));

If you do not perform this conversion, the compiler assumes that you are trying to call the SqlParameter (string, SqlDbType) constructor overload.

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

Private Sub AddSqlParameter(ByVal command As SqlCommand)

    Dim parameter As New SqlParameter("@Description", _
        SqlDbType.VarChar, 88, "Description")
    With parameter
        .IsNullable = True
        .Direction = ParameterDirection.Output
    End With

    command.Parameters.Add(parameter)
End Sub

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft