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 override System.Data.DbType DbType { get; set; }
member this.DbType : System.Data.DbType with get, set
Public Overrides Property DbType As DbType

Property Value

One of the SqlDbType values. The default is NVarChar.

Implements

Examples

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

using Microsoft.Data.SqlClient;

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

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