Export (0) Print
Expand All

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 (ADO.NET).

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

[<Sealed>]
type SqlParameter =  
    class
        inherit DbParameter
        interface IDbDataParameter
        interface IDataParameter
        interface ICloneable
    end

The SqlParameter type exposes the following members.

  NameDescription
Public methodSqlParameter()Initializes a new instance of the SqlParameter class.
Public methodSqlParameter(String, SqlDbType)Initializes a new instance of the SqlParameter class that uses the parameter name and the data type.
Public methodSqlParameter(String, Object)Initializes a new instance of the SqlParameter class that uses the parameter name and a value of the new SqlParameter.
Public methodSqlParameter(String, SqlDbType, Int32)Initializes a new instance of the SqlParameter class that uses the parameter name, the SqlDbType, and the size.
Public methodSqlParameter(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.
Public methodSqlParameter(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.
Public methodSqlParameter(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.
Top

  NameDescription
Public propertyCompareInfoGets or sets the CompareInfo object that defines how string comparisons should be performed for this parameter.
Public propertyDbTypeGets or sets the SqlDbType of the parameter. (Overrides DbParameter.DbType.)
Public propertyDirectionGets 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.)
Public propertyIsNullableGets or sets a value that indicates whether the parameter accepts null values. (Overrides DbParameter.IsNullable.)
Public propertyLocaleIdGets or sets the locale identifier that determines conventions and language for a particular region.
Public propertyOffsetGets or sets the offset to the Value property.
Public propertyParameterNameGets or sets the name of the SqlParameter. (Overrides DbParameter.ParameterName.)
Public propertyPrecisionGets or sets the maximum number of digits used to represent the Value property.
Public propertyScaleGets or sets the number of decimal places to which Value is resolved.
Public propertySizeGets or sets the maximum size, in bytes, of the data within the column. (Overrides DbParameter.Size.)
Public propertySourceColumnGets or sets the name of the source column mapped to the DataSet and used for loading or returning the Value (Overrides DbParameter.SourceColumn.)
Public propertySourceColumnNullMappingSets 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.)
Public propertySourceVersionGets or sets the DataRowVersion to use when you load Value (Overrides DbParameter.SourceVersion.)
Public propertySqlDbTypeGets or sets the SqlDbType of the parameter.
Public propertySqlValueGets or sets the value of the parameter as an SQL type.
Public propertyTypeNameGets or sets the type name for a table-valued parameter.
Public propertyUdtTypeNameGets or sets a string that represents a user-defined type as a parameter.
Public propertyValueGets or sets the value of the parameter. (Overrides DbParameter.Value.)
Public propertyXmlSchemaCollectionDatabaseGets the name of the database where the schema collection for this XML instance is located.
Public propertyXmlSchemaCollectionNameGets the name of the schema collection for this XML instance.
Public propertyXmlSchemaCollectionOwningSchemaThe owning relational schema where the schema collection for this XML instance is located.
Top

  NameDescription
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodMemberwiseClone()Creates a shallow copy of the current Object. (Inherited from Object.)
Protected methodMemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Public methodResetDbTypeResets the type associated with this SqlParameter. (Overrides DbParameter.ResetDbType().)
Public methodResetSqlDbTypeResets the type associated with this SqlParameter.
Public methodToStringGets a string that contains the ParameterName. (Overrides Object.ToString().)
Top

  NameDescription
Explicit interface implemetationPrivate methodICloneable.CloneFor a description of this member, see Clone.
Explicit interface implemetationPrivate propertyIDbDataParameter.PrecisionIndicates the precision of numeric parameters. (Inherited from DbParameter.)
Explicit interface implemetationPrivate propertyIDbDataParameter.ScaleFor a description of this member, see IDbDataParameter.Scale. (Inherited from DbParameter.)
Top

Parameter names are not case sensitive.

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

NoteNote

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

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 (ADO.NET).

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

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

Community Additions

ADD
Show:
© 2014 Microsoft