SqlCeParameterCollection Class

Collects all parameters relevant to a SqlCeCommand as well as their respective mappings to DataSet columns.


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

public sealed class SqlCeParameterCollection : DbParameterCollection

The SqlCeParameterCollection type exposes the following members.

Public propertyCountGets the number of SqlCeParameter objects in the collection. (Overrides DbParameterCollection.Count.)
Public propertyIsFixedSizeInfrastructure. (Overrides DbParameterCollection.IsFixedSize.)
Public propertyIsReadOnlyInfrastructure. (Overrides DbParameterCollection.IsReadOnly.)
Public propertyIsSynchronizedInfrastructure. (Overrides DbParameterCollection.IsSynchronized.)
Public propertyItem[Int32]Gets or sets the SqlCeParameter at the specified index.
Public propertyItem[String]Gets or sets the SqlCeParameter with the specified name.
Public propertySyncRootInfrastructure. (Overrides DbParameterCollection.SyncRoot.)

Public methodAdd(Object)Adds a SqlCeParameter object to the SqlCeCommand. (Overrides DbParameterCollection.Add(Object).)
Public methodAdd(SqlCeParameter)Adds the specified SqlCeParameter to the SqlCeParameterCollection.
Public methodAdd(String, SqlDbType)Adds a SqlCeParameter to the SqlCeParameterCollection given the parameter name and data type.
Public methodAdd(String, Object) Obsolete. Adds a SqlCeParameter to the SqlCeParameterCollection given the parameter name and value.
Public methodAdd(String, SqlDbType, Int32)Adds a SqlCeParameter to the SqlCeParameterCollection given the parameter name, data type, and column width.
Public methodAdd(String, SqlDbType, Int32, String)Adds a SqlCeParameter to the SqlCeCommand given the parameter name, data type, column width, and source column name.
Public methodAddRangeAdds an array of SqlCeParameter objects to SqlCeParameterCollection. (Overrides DbParameterCollection.AddRange(Array).)
Public methodAddWithValueAdds a new SqlCeParameter to the SqlCeParameterCollection and sets its value.
Public methodClearRemoves all items from the collection. (Overrides DbParameterCollection.Clear().)
Public methodContains(Object)Gets a value indicating whether or not a SqlCeParameter object exists in the collection. (Overrides DbParameterCollection.Contains(Object).)
Public methodContains(String)Gets a value indicating whether a SqlCeParameter with the specified parameter name exists in the collection. (Overrides DbParameterCollection.Contains(String).)
Public methodCopyToCopies SqlCeParameter objects from the SqlCeParameterCollection to the specified array. (Overrides DbParameterCollection.CopyTo(Array, Int32).)
Public methodCreateObjRef (inherited from MarshalByRefObject)
Public methodEquals (inherited from Object)
Protected methodFinalize (inherited from Object)
Public methodGetEnumeratorInfrastructure. (Overrides DbParameterCollection.GetEnumerator().)
Public methodGetHashCode (inherited from Object)
Public methodGetLifetimeService (inherited from MarshalByRefObject)
Protected methodGetParameter(Int32) (inherited from DbParameterCollection)
Protected methodGetParameter(String) (inherited from DbParameterCollection)
Public methodGetType (inherited from Object)
Public methodIndexOf(Object)Gets the location of the SqlCeParameter object in the collection. (Overrides DbParameterCollection.IndexOf(Object).)
Public methodIndexOf(String)Gets the location of the SqlCeParameter in the collection with the specified parameter name. (Overrides DbParameterCollection.IndexOf(String).)
Public methodInitializeLifetimeService (inherited from MarshalByRefObject)
Public methodInsertInserts a SqlCeParameter in the collection at the specified index. (Overrides DbParameterCollection.Insert(Int32, Object).)
Protected methodMemberwiseClone() (inherited from Object)
Protected methodMemberwiseClone(Boolean) (inherited from MarshalByRefObject)
Public methodRemoveRemoves the specified SqlCeParameter from the collection. (Overrides DbParameterCollection.Remove(Object).)
Public methodRemoveAt(Int32)Removes the SqlCeParameter at the specified index from the collection. (Overrides DbParameterCollection.RemoveAt(Int32).)
Public methodRemoveAt(String)Removes the SqlCeParameter with the specified name from the collection. (Overrides DbParameterCollection.RemoveAt(String).)
Protected methodSetParameter(Int32, DbParameter) (inherited from DbParameterCollection)
Protected methodSetParameter(String, DbParameter) (inherited from DbParameterCollection)
Public methodToString (inherited from Object)

Explicit interface implemetationPrivate propertyIList.Item (inherited from DbParameterCollection)
Explicit interface implemetationPrivate propertyIDataParameterCollection.Item (inherited from DbParameterCollection)

The number of parameters in the collection must be equal to the number of parameter placeholders within the command text. Otherwise, the .NET Compact Framework Data Provider for SQL Server Compact may raise an error.

The following example creates multiple instances of SqlCeParameter through the SqlCeParameterCollection collection within the SqlCeDataAdapter. These parameters are used to select data within the data source. Then they place the data in the DataSet. This example assumes that a DataSet and a SqlCeDataAdapter have already been created with the appropriate schema, commands, and connection.

SqlCeCommand cmd = null;
SqlCeDataAdapter adp = null;

    adp = new SqlCeDataAdapter();
    SqlCeConnection conn = new SqlCeConnection("Data Source = MyDatabase.sdf");

    // Create the SelectCommand
    cmd = conn.CreateCommand();
    cmd.CommandText = "SELECT * FROM Orders WHERE [Ship Country] = @country AND [Ship City] = @city";
    cmd.Parameters.Add("@country", SqlDbType.NVarChar, 15);
    cmd.Parameters.Add("@city", SqlDbType.NVarChar, 15);

    cmd.Parameters["@country"].Value = "UK";
    cmd.Parameters["@city"].Value = "London";

    adp.SelectCommand = cmd;

    // Create the DeleteCommand
    cmd = conn.CreateCommand();
    cmd.CommandText = "DELETE FROM Orders WHERE [Order ID] = @orderID";

    SqlCeParameter p = cmd.Parameters.Add("@orderID", SqlDbType.NChar, 5, "Order ID");
    p.SourceVersion = DataRowVersion.Original;

    adp.DeleteCommand = cmd;

    // Populate the dataset with the results from the SELECT statement
    DataSet ds = new DataSet();

    // Modify the dataset
    MessageBox.Show("Number of rows: " + ds.Tables[0].Rows.Count);

    // Delete some rows

    // This will execute two DELETE statements 
catch (Exception e)
    if (null != adp.SelectCommand) adp.SelectCommand.Dispose();
    if (null != adp.DeleteCommand) adp.DeleteCommand.Dispose();

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