SqlParameter Class
Collapse the table of content
Expand the table of content

SqlParameter Class

 

Represents a parameter to a SqlCommand and optionally its mapping to DataSet columns. This class cannot be inherited. For more information on parameters, see Configuring Parameters and Parameter Data Types.

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

System.Object
  System.MarshalByRefObject
    System.Data.Common.DbParameter
      System.Data.SqlClient.SqlParameter

public sealed class SqlParameter : DbParameter, IDbDataParameter, 
	IDataParameter, ICloneable

NameDescription
System_CAPS_pubmethodSqlParameter()

Initializes a new instance of the SqlParameter class.

System_CAPS_pubmethodSqlParameter(String, Object)

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

System_CAPS_pubmethodSqlParameter(String, SqlDbType)

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

System_CAPS_pubmethodSqlParameter(String, SqlDbType, Int32)

Initializes a new instance of the SqlParameter class that uses the parameter name, the SqlDbType, and the size.

System_CAPS_pubmethodSqlParameter(String, SqlDbType, Int32, ParameterDirection, Boolean, Byte, Byte, String, DataRowVersion, Object)

Initializes a new instance of the SqlParameter class that uses the parameter name, the type of the parameter, the size of the parameter, a ParameterDirection, the precision of the parameter, the scale of the parameter, the source column, a DataRowVersion to use, and the value of the parameter.

System_CAPS_pubmethodSqlParameter(String, SqlDbType, Int32, ParameterDirection, Byte, Byte, String, DataRowVersion, Boolean, Object, String, String, String)

Initializes a new instance of the SqlParameter class that uses the parameter name, the type of the parameter, the length of the parameter the direction, the precision, the scale, the name of the source column, one of the DataRowVersion values, a Boolean for source column mapping, the value of the SqlParameter, the name of the database where the schema collection for this XML instance is located, the owning relational schema where the schema collection for this XML instance is located, and the name of the schema collection for this parameter.

System_CAPS_pubmethodSqlParameter(String, SqlDbType, Int32, String)

Initializes a new instance of the SqlParameter class that uses the parameter name, the SqlDbType, the size, and the source column name.

NameDescription
System_CAPS_pubpropertyCompareInfo

Gets or sets the CompareInfo object that defines how string comparisons should be performed for this parameter.

System_CAPS_pubpropertyDbType

Gets or sets the SqlDbType of the parameter.(Overrides DbParameter.DbType.)

System_CAPS_pubpropertyDirection

Gets or sets a value that indicates whether the parameter is input-only, output-only, bidirectional, or a stored procedure return value parameter.(Overrides DbParameter.Direction.)

System_CAPS_pubpropertyForceColumnEncryption

Enforces encryption of a parameter when using Always Encrypted. If SQL Server informs the driver that the parameter does not need to be encrypted, the query using the parameter will fail. This property provides additional protection against security attacks that involve a compromised SQL Server providing incorrect encryption metadata to the client, which may lead to data disclosure.

System_CAPS_pubpropertyIsNullable

Gets or sets a value that indicates whether the parameter accepts null values. IsNullable is not used to validate the parameter’s value and will not prevent sending or receiving a null value when executing a command.(Overrides DbParameter.IsNullable.)

System_CAPS_pubpropertyLocaleId

Gets or sets the locale identifier that determines conventions and language for a particular region.

System_CAPS_pubpropertyOffset

Gets or sets the offset to the Value property.

System_CAPS_pubpropertyParameterName

Gets or sets the name of the SqlParameter.(Overrides DbParameter.ParameterName.)

System_CAPS_pubpropertyPrecision

Gets or sets the maximum number of digits used to represent the Value property.

System_CAPS_pubpropertyScale

Gets or sets the number of decimal places to which Value is resolved.

System_CAPS_pubpropertySize

Gets or sets the maximum size, in bytes, of the data within the column.(Overrides DbParameter.Size.)

System_CAPS_pubpropertySourceColumn

Gets or sets the name of the source column mapped to the DataSet and used for loading or returning the Value(Overrides DbParameter.SourceColumn.)

System_CAPS_pubpropertySourceColumnNullMapping

Sets or gets a value which indicates whether the source column is nullable. This allows SqlCommandBuilder to correctly generate Update statements for nullable columns.(Overrides DbParameter.SourceColumnNullMapping.)

System_CAPS_pubpropertySourceVersion

Gets or sets the DataRowVersion to use when you load Value(Overrides DbParameter.SourceVersion.)

System_CAPS_pubpropertySqlDbType

Gets or sets the SqlDbType of the parameter.

System_CAPS_pubpropertySqlValue

Gets or sets the value of the parameter as an SQL type.

System_CAPS_pubpropertyTypeName

Gets or sets the type name for a table-valued parameter.

System_CAPS_pubpropertyUdtTypeName

Gets or sets a string that represents a user-defined type as a parameter.

System_CAPS_pubpropertyValue

Gets or sets the value of the parameter.(Overrides DbParameter.Value.)

System_CAPS_pubpropertyXmlSchemaCollectionDatabase

Gets the name of the database where the schema collection for this XML instance is located.

System_CAPS_pubpropertyXmlSchemaCollectionName

Gets the name of the schema collection for this XML instance.

System_CAPS_pubpropertyXmlSchemaCollectionOwningSchema

The owning relational schema where the schema collection for this XML instance is located.

NameDescription
System_CAPS_pubmethodCreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodInitializeLifetimeService()

Obtains a lifetime service object to control the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodResetDbType()

Resets the type associated with this SqlParameter.(Overrides DbParameter.ResetDbType().)

System_CAPS_pubmethodResetSqlDbType()

Resets the type associated with this SqlParameter.

System_CAPS_pubmethodToString()

Gets a string that contains the ParameterName.(Overrides Object.ToString().)

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodICloneable.Clone()

For a description of this member, see Clone.

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIDbDataParameter.Precision

Indicates the precision of numeric parameters.(Inherited from DbParameter.)

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIDbDataParameter.Scale

For a description of this member, see IDbDataParameter.Scale.(Inherited from DbParameter.)

Parameter names are not case sensitive.

System_CAPS_noteNote

Nameless, also called ordinal, parameters are not supported by the .NET Framework Data Provider for SQL Server.

For more information, along with additional sample code demonstrating how to use parameters, see Commands and Parameters.

The following example creates multiple instances of SqlParameter through the SqlParameterCollection collection within the SqlDataAdapter. These parameters are used to select data from the data source and put the data in the DataSet. This example assumes that a DataSet and a SqlDataAdapter have already been created by using the appropriate schema, commands, and connection. For more information and additional examples on using parameters, see Retrieving and Modifying Data in ADO.NET and Configuring Parameters and Parameter Data Types.

public void AddSqlParameters() 
{
// ...
// create categoriesDataSet and categoriesAdapter
// ...

  categoriesAdapter.SelectCommand.Parameters.Add(
    "@CategoryName", SqlDbType.VarChar, 80).Value = "toasters";
  categoriesAdapter.SelectCommand.Parameters.Add(
    "@SerialNum", SqlDbType.Int).Value = 239;
  categoriesAdapter.Fill(categoriesDataSet);

}

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show:
© 2016 Microsoft