SqlParameter.DbType Property

 

Gets or sets the SqlDbType of the parameter.

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

public override DbType DbType { get; set; }

Property Value

Type: System.Data.DbType

One of the SqlDbType values. The default is NVarChar.

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.

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");
    }
}

.NET Framework
Available since 1.1
Return to top
Show: