SqlCeParameterCollection Class
Collects all parameters relevant to a SqlCeCommand as well as their respective mappings to DataSet columns.
Inheritance Hierarchy
System.Object
System.MarshalByRefObject
System.Data.Common.DbParameterCollection
System.Data.SqlServerCe.SqlCeParameterCollection
Namespace: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (in System.Data.SqlServerCe.dll)
Syntax
'Declaration
Public NotInheritable Class SqlCeParameterCollection _
Inherits DbParameterCollection
'Usage
Dim instance As SqlCeParameterCollection
public sealed class SqlCeParameterCollection : DbParameterCollection
public ref class SqlCeParameterCollection sealed : public DbParameterCollection
[<SealedAttribute>]
type SqlCeParameterCollection =
class
inherit DbParameterCollection
end
public final class SqlCeParameterCollection extends DbParameterCollection
The SqlCeParameterCollection type exposes the following members.
Properties
Name | Description | |
---|---|---|
Count | Gets the number of SqlCeParameter objects in the collection. (Overrides DbParameterCollection.Count.) | |
IsFixedSize | Infrastructure. (Overrides DbParameterCollection.IsFixedSize.) | |
IsReadOnly | Infrastructure. (Overrides DbParameterCollection.IsReadOnly.) | |
IsSynchronized | Infrastructure. (Overrides DbParameterCollection.IsSynchronized.) | |
Item[Int32] | Gets or sets the SqlCeParameter at the specified index. | |
Item[String] | Gets or sets the SqlCeParameter with the specified name. | |
SyncRoot | Infrastructure. (Overrides DbParameterCollection.SyncRoot.) |
Top
Methods
Name | Description | |
---|---|---|
Add(Object) | Adds a SqlCeParameter object to the SqlCeCommand. (Overrides DbParameterCollection.Add(Object).) | |
Add(SqlCeParameter) | Adds the specified SqlCeParameter to the SqlCeParameterCollection. | |
Add(String, SqlDbType) | Adds a SqlCeParameter to the SqlCeParameterCollection given the parameter name and data type. | |
Add(String, Object) | Obsolete. Adds a SqlCeParameter to the SqlCeParameterCollection given the parameter name and value. | |
Add(String, SqlDbType, Int32) | Adds a SqlCeParameter to the SqlCeParameterCollection given the parameter name, data type, and column width. | |
Add(String, SqlDbType, Int32, String) | Adds a SqlCeParameter to the SqlCeCommand given the parameter name, data type, column width, and source column name. | |
AddRange | Adds an array of SqlCeParameter objects to SqlCeParameterCollection. (Overrides DbParameterCollection.AddRange(Array).) | |
AddWithValue | Adds a new SqlCeParameter to the SqlCeParameterCollection and sets its value. | |
Clear | Removes all items from the collection. (Overrides DbParameterCollection.Clear().) | |
Contains(Object) | Gets a value indicating whether or not a SqlCeParameter object exists in the collection. (Overrides DbParameterCollection.Contains(Object).) | |
Contains(String) | Gets a value indicating whether a SqlCeParameter with the specified parameter name exists in the collection. (Overrides DbParameterCollection.Contains(String).) | |
CopyTo | Copies SqlCeParameter objects from the SqlCeParameterCollection to the specified array. (Overrides DbParameterCollection.CopyTo(Array, Int32).) | |
CreateObjRef | (inherited from MarshalByRefObject) | |
Equals | (inherited from Object) | |
Finalize | (inherited from Object) | |
GetEnumerator | Infrastructure. (Overrides DbParameterCollection.GetEnumerator().) | |
GetHashCode | (inherited from Object) | |
GetLifetimeService | (inherited from MarshalByRefObject) | |
GetParameter(Int32) | (inherited from DbParameterCollection) | |
GetParameter(String) | (inherited from DbParameterCollection) | |
GetType | (inherited from Object) | |
IndexOf(Object) | Gets the location of the SqlCeParameter object in the collection. (Overrides DbParameterCollection.IndexOf(Object).) | |
IndexOf(String) | Gets the location of the SqlCeParameter in the collection with the specified parameter name. (Overrides DbParameterCollection.IndexOf(String).) | |
InitializeLifetimeService | (inherited from MarshalByRefObject) | |
Insert | Inserts a SqlCeParameter in the collection at the specified index. (Overrides DbParameterCollection.Insert(Int32, Object).) | |
MemberwiseClone() | (inherited from Object) | |
MemberwiseClone(Boolean) | (inherited from MarshalByRefObject) | |
Remove | Removes the specified SqlCeParameter from the collection. (Overrides DbParameterCollection.Remove(Object).) | |
RemoveAt(Int32) | Removes the SqlCeParameter at the specified index from the collection. (Overrides DbParameterCollection.RemoveAt(Int32).) | |
RemoveAt(String) | Removes the SqlCeParameter with the specified name from the collection. (Overrides DbParameterCollection.RemoveAt(String).) | |
SetParameter(Int32, DbParameter) | (inherited from DbParameterCollection) | |
SetParameter(String, DbParameter) | (inherited from DbParameterCollection) | |
ToString | (inherited from Object) |
Top
Explicit Interface Implementations
Name | Description | |
---|---|---|
IList.Item | (inherited from DbParameterCollection) | |
IDataParameterCollection.Item | (inherited from DbParameterCollection) |
Top
Remarks
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.
Examples
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.
Dim cmd As SqlCeCommand = Nothing
Dim adp As SqlCeDataAdapter = Nothing
Try
adp = New SqlCeDataAdapter()
Dim conn As 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"
Dim p As SqlCeParameter = 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
'
Dim ds As New DataSet()
adp.Fill(ds)
' Modify the dataset
'
MessageBox.Show("Number of rows: " & ds.Tables(0).Rows.Count)
' Delete some rows
'
ds.Tables(0).Rows(3).Delete()
ds.Tables(0).Rows(4).Delete()
' This will execute two DELETE statements
'
adp.Update(ds.Tables(0))
Catch e As Exception
MessageBox.Show(e.Message)
Finally
If Not Nothing Is adp.SelectCommand Then
adp.SelectCommand.Dispose()
End If
If Not Nothing Is adp.DeleteCommand Then
adp.DeleteCommand.Dispose()
End If
End Try
SqlCeCommand cmd = null;
SqlCeDataAdapter adp = null;
try
{
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();
adp.Fill(ds);
// Modify the dataset
//
MessageBox.Show("Number of rows: " + ds.Tables[0].Rows.Count);
// Delete some rows
//
ds.Tables[0].Rows[3].Delete();
ds.Tables[0].Rows[4].Delete();
// This will execute two DELETE statements
//
adp.Update(ds.Tables[0]);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
finally
{
if (null != adp.SelectCommand) adp.SelectCommand.Dispose();
if (null != adp.DeleteCommand) adp.DeleteCommand.Dispose();
}
Thread Safety
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.