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
/** @attribute DefaultMemberAttribute("Item") */ 
public final class SqlCeParameterCollection extends DbParameterCollection
public final class SqlCeParameterCollection extends 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 3.5 SP1 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.

Development Platforms

Windows Vista, Windows Mobile 5.0, Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Mobile 2003 for Pocket PC, Windows CE 5.0
Version Information
.NET Framework and NET Compact Framework
Supported in 3.5
.NET Framework
Supported in 3.0
.NET Compact Framework and .Net Framework
Supported in 2.0