Επεξεργασία

Κοινή χρήση μέσω


SqlParameter.DbType Property

Definition

Gets or sets the SqlDbType of the parameter.

public:
 virtual property System::Data::DbType DbType { System::Data::DbType get(); void set(System::Data::DbType value); };
public:
 property System::Data::DbType DbType { System::Data::DbType get(); void set(System::Data::DbType value); };
public override System.Data.DbType DbType { get; set; }
[System.ComponentModel.Browsable(false)]
[System.Data.DataSysDescription("DataParameter_DbType")]
public System.Data.DbType DbType { get; set; }
member this.DbType : System.Data.DbType with get, set
[<System.ComponentModel.Browsable(false)>]
[<System.Data.DataSysDescription("DataParameter_DbType")>]
member this.DbType : System.Data.DbType with get, set
Public Overrides Property DbType As DbType
Public Property DbType As DbType

Property Value

One of the SqlDbType values. The default is NVarChar.

Implements

Attributes

Examples

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

    private static void AddSqlParameter(SqlCommand command,
        string paramValue)
    {
        SqlParameter parameter = new SqlParameter(
            "@Description", SqlDbType.VarChar);
        parameter.Value = paramValue;
        parameter.IsNullable = true;
        command.Parameters.Add(parameter);
    }

private static void SetParameterToNull(IDataParameter parameter)
{
    if (parameter.IsNullable)
    {
        parameter.Value = DBNull.Value;
    }
    else
    {
        throw new ArgumentException("Parameter provided is not nullable", "parameter");
    }
}
 Private Sub AddSqlParameter(ByVal command As SqlCommand, _
     ByVal paramValue As String)

     Dim parameter As New SqlParameter( _
         "@Description", SqlDbType.NVarChar, 16)
     parameter.Value = paramValue
     parameter.IsNullable = True
     command.Parameters.Add(parameter)
 End Sub

 Private Shared Sub SetParameterToNull(parameter As IDataParameter)
     If parameter.IsNullable Then
     parameter.Value = DBNull.Value
     Else
         Throw New ArgumentException("Parameter provided is not nullable", "parameter")
     End If
End Sub

Remarks

The SqlDbType and DbType are linked. Therefore, setting the DbType changes the SqlDbType to a supporting SqlDbType.

For a list of the supported data types, see the appropriate SqlDbType member. For more information, see DataAdapter Parameters.

Applies to

See also