SqlParameterCollection Class
Collapse the table of content
Expand the table of content

SqlParameterCollection Class

 

Represents a collection of parameters associated with a SqlCommand and their respective mappings to columns in a DataSet. This class cannot be inherited.

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

System.Object
  System.MarshalByRefObject
    System.Data.Common.DbParameterCollection
      System.Data.SqlClient.SqlParameterCollection

[ListBindableAttribute(false)]
public sealed class SqlParameterCollection : DbParameterCollection

NameDescription
System_CAPS_pubpropertyCount

Returns an Integer that contains the number of elements in the SqlParameterCollection. Read-only. (Overrides DbParameterCollection.Count.)

System_CAPS_pubpropertyIsFixedSize

Gets a value that indicates whether the SqlParameterCollection has a fixed size. (Overrides DbParameterCollection.IsFixedSize.)

System_CAPS_pubpropertyIsReadOnly

Gets a value that indicates whether the SqlParameterCollection is read-only. (Overrides DbParameterCollection.IsReadOnly.)

System_CAPS_pubpropertyIsSynchronized

Gets a value that indicates whether the SqlParameterCollection is synchronized.(Overrides DbParameterCollection.IsSynchronized.)

System_CAPS_pubpropertyItem[Int32]

Gets the SqlParameter at the specified index.

System_CAPS_pubpropertyItem[String]

Gets the SqlParameter with the specified name.

System_CAPS_pubpropertySyncRoot

Gets an object that can be used to synchronize access to the SqlParameterCollection. (Overrides DbParameterCollection.SyncRoot.)

NameDescription
System_CAPS_pubmethodAdd(Object)

Adds the specified SqlParameter object to the SqlParameterCollection.(Overrides DbParameterCollection.Add(Object).)

System_CAPS_pubmethodAdd(SqlParameter)

Adds the specified SqlParameter object to the SqlParameterCollection.

System_CAPS_pubmethodAdd(String, Object)

Obsolete.Adds the specified SqlParameter object to the SqlParameterCollection.

System_CAPS_pubmethodAdd(String, SqlDbType)

Adds a SqlParameter to the SqlParameterCollection given the parameter name and the data type.

System_CAPS_pubmethodAdd(String, SqlDbType, Int32)

Adds a SqlParameter to the SqlParameterCollection, given the specified parameter name, SqlDbType and size.

System_CAPS_pubmethodAdd(String, SqlDbType, Int32, String)

Adds a SqlParameter to the SqlParameterCollection with the parameter name, the data type, and the column length.

System_CAPS_pubmethodAddRange(Array)

Adds an array of values to the end of the SqlParameterCollection.(Overrides DbParameterCollection.AddRange(Array).)

System_CAPS_pubmethodAddRange(SqlParameter[])

Adds an array of SqlParameter values to the end of the SqlParameterCollection.

System_CAPS_pubmethodAddWithValue(String, Object)

Adds a value to the end of the SqlParameterCollection.

System_CAPS_pubmethodClear()

Removes all the SqlParameter objects from the SqlParameterCollection.(Overrides DbParameterCollection.Clear().)

System_CAPS_pubmethodContains(Object)

Determines whether the specified Object is in this SqlParameterCollection.(Overrides DbParameterCollection.Contains(Object).)

System_CAPS_pubmethodContains(SqlParameter)

Determines whether the specified SqlParameter is in this SqlParameterCollection.

System_CAPS_pubmethodContains(String)

Determines whether the specified parameter name is in this SqlParameterCollection.(Overrides DbParameterCollection.Contains(String).)

System_CAPS_pubmethodCopyTo(Array, Int32)

Copies all the elements of the current SqlParameterCollection to the specified one-dimensional Array starting at the specified destination Array index.(Overrides DbParameterCollection.CopyTo(Array, Int32).)

System_CAPS_pubmethodCopyTo(SqlParameter[], Int32)

Copies all the elements of the current SqlParameterCollection to the specified SqlParameterCollection starting at the specified destination index.

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_pubmethodGetEnumerator()

Returns an enumerator that iterates through the SqlParameterCollection. (Overrides DbParameterCollection.GetEnumerator().)

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_pubmethodIndexOf(Object)

Gets the location of the specified Object within the collection.(Overrides DbParameterCollection.IndexOf(Object).)

System_CAPS_pubmethodIndexOf(SqlParameter)

Gets the location of the specified SqlParameter within the collection.

System_CAPS_pubmethodIndexOf(String)

Gets the location of the specified SqlParameter with the specified name.(Overrides DbParameterCollection.IndexOf(String).)

System_CAPS_pubmethodInitializeLifetimeService()

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

System_CAPS_pubmethodInsert(Int32, Object)

Inserts an Object into the SqlParameterCollection at the specified index.(Overrides DbParameterCollection.Insert(Int32, Object).)

System_CAPS_pubmethodInsert(Int32, SqlParameter)

Inserts a SqlParameter object into the SqlParameterCollection at the specified index.

System_CAPS_pubmethodRemove(Object)

Removes the specified SqlParameter from the collection.(Overrides DbParameterCollection.Remove(Object).)

System_CAPS_pubmethodRemove(SqlParameter)

Removes the specified SqlParameter from the collection.

System_CAPS_pubmethodRemoveAt(Int32)

Removes the SqlParameter from the SqlParameterCollection at the specified index.(Overrides DbParameterCollection.RemoveAt(Int32).)

System_CAPS_pubmethodRemoveAt(String)

Removes the SqlParameter from the SqlParameterCollection at the specified parameter name.(Overrides DbParameterCollection.RemoveAt(String).)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privpropertyIList.Item[Int32]

Gets or sets the element at the specified index.(Inherited from DbParameterCollection.)

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIDataParameterCollection.Item[String]

Gets or sets the parameter at the specified index.(Inherited from DbParameterCollection.)

NameDescription
System_CAPS_pubmethodAsParallel()

Overloaded. Enables parallelization of a query.(Defined by ParallelEnumerable.)

System_CAPS_pubmethodAsQueryable()

Overloaded. Converts an IEnumerable to an IQueryable.(Defined by Queryable.)

System_CAPS_pubmethodCast<TResult>()

Casts the elements of an IEnumerable to the specified type.(Defined by Enumerable.)

System_CAPS_pubmethodOfType<TResult>()

Filters the elements of an IEnumerable based on a specified type.(Defined by Enumerable.)

If the command contains an ad hoc SQL statement, as opposed to a stored-procedure name, the number of the parameters in the collection must be equal to the number of parameter placeholders within the command text, or SQL Server raises an error. With a stored procedure, all the parameters declared in the stored procedure without a default value must be provided. Parameters declared with a default value are optional. This lets you specify a value other than the default.

For more information 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. The parameters are used to select data within the data source and populate the DataSet. This code assumes that a DataSet and a SqlDataAdapter have already been created with the appropriate schema, commands, and connection.

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