Click or drag to resize

MySqlParameterCollection Class

Represents a collection of parameters relevant to a MySqlCommand as well as their respective mappings to columns in a DataSet. This class cannot be inherited.
Inheritance Hierarchy

Namespace:  MySql.Data.MySqlClient
Assembly:  MySql.Data (in MySql.Data.dll) Version: 8.0.22
Syntax
public sealed class MySqlParameterCollection : DbParameterCollection

The MySqlParameterCollection type exposes the following members.

Properties
Methods
  NameDescription
Public methodAdd(Object)
Adds the specified MySqlParameter object to the MySqlParameterCollection.
(Overrides DbParameterCollectionAdd(Object).)
Public methodAdd(MySqlParameter)
Adds the specified MySqlParameter object to the MySqlParameterCollection.
Public methodAdd(String, MySqlDbType)
Adds a MySqlParameter to the MySqlParameterCollection given the parameter name and the data type.
Public methodAdd(String, MySqlDbType, Int32)
Adds a MySqlParameter to the MySqlParameterCollection with the parameter name, the data type, and the column length.
Public methodAdd(String, MySqlDbType, Int32, String)
Adds a MySqlParameter to the MySqlParameterCollection with the parameter name, the data type, the column length, and the source column name.
Public methodAddRange
Adds an array of values to the end of the MySqlParameterCollection.
(Overrides DbParameterCollectionAddRange(Array).)
Public methodAddWithValue
Adds a parameter and its value.
Public methodClear
Removes all items from the collection.
(Overrides DbParameterCollectionClear.)
Public methodContains(Object)
Gets a value indicating whether a MySqlParameter exists in the collection.
(Overrides DbParameterCollectionContains(Object).)
Public methodContains(String)
Gets a value indicating whether a MySqlParameter with the specified parameter name exists in the collection.
(Overrides DbParameterCollectionContains(String).)
Public methodCopyTo
Copies MySqlParameter objects from the MySqlParameterCollection to the specified array.
(Overrides DbParameterCollectionCopyTo(Array, Int32).)
Public methodCreateObjRef
Creates 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
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetEnumerator
Returns an enumerator that iterates through the MySqlParameterCollection.
(Overrides DbParameterCollection.GetEnumerator.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetLifetimeService
Retrieves the current lifetime service object that controls the lifetime policy for this instance.
(Inherited from MarshalByRefObject.)
Protected methodGetParameter(Int32) (Overrides DbParameterCollectionGetParameter(Int32).)
Protected methodGetParameter(String)
Retrieve the parameter with the given name.
(Overrides DbParameterCollectionGetParameter(String).)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodIndexOf(Object)
Gets the location of a MySqlParameter in the collection.
(Overrides DbParameterCollectionIndexOf(Object).)
Public methodIndexOf(String)
Gets the location of the MySqlParameter in the collection with a specific parameter name.
(Overrides DbParameterCollectionIndexOf(String).)
Public methodInitializeLifetimeService
Obtains a lifetime service object to control the lifetime policy for this instance.
(Inherited from MarshalByRefObject.)
Public methodInsert
Inserts a MySqlParameter into the collection at the specified index.
(Overrides DbParameterCollectionInsert(Int32, Object).)
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 methodRemove
Removes the specified MySqlParameter from the collection.
(Overrides DbParameterCollectionRemove(Object).)
Public methodRemoveAt(Int32)
Removes the specified MySqlParameter from the collection using a specific index.
(Overrides DbParameterCollectionRemoveAt(Int32).)
Public methodRemoveAt(String)
Removes the specified MySqlParameter from the collection using the parameter name.
(Overrides DbParameterCollectionRemoveAt(String).)
Protected methodSetParameter(Int32, DbParameter) (Overrides DbParameterCollectionSetParameter(Int32, DbParameter).)
Protected methodSetParameter(String, DbParameter) (Overrides DbParameterCollectionSetParameter(String, DbParameter).)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Remarks
The number of the parameters in the collection must be equal to the number of parameter placeholders within the command text, or an exception will be generated.
Examples
The following example creates multiple instances of MySqlParameter through the MySqlParameterCollection collection within the MySqlDataAdapter. These parameters are used to select data within the data source and place the data in the DataSet. This code assumes that a DataSet and a MySqlDataAdapter have already been created with the appropriate schema, commands, and connection.
public void AddSqlParameters()
{
// ...
// create myDataSet and myDataAdapter
// ...

myDataAdapter.SelectCommand.Parameters.Add("@CategoryName", MySqlDbType.VarChar, 80).Value = "toasters";
myDataAdapter.SelectCommand.Parameters.Add("@SerialNum", MySqlDbType.Long).Value = 239;
myDataAdapter.Fill(myDataSet);

}
See Also