SqlCeCommand.Parameters Property
Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.
Gets the SqlCeParameterCollection.
[Visual Basic] Public ReadOnly Property Parameters As SqlCeParameterCollection [C#] public SqlCeParameterCollection Parameters {get;} [C++] public: __property SqlCeParameterCollection* get_Parameters(); [JScript] public function get Parameters() : SqlCeParameterCollection;
Property Value
The parameters of the SQL statement. The default is an empty collection.
Remarks
The .NET Compact Framework data provider for SQL Server CE does not support named parameters for passing parameters to an SQL statement called by a SqlCeCommand when CommandType is set to Text. You must use the question mark (?) placeholder. For example: SELECT * FROM Customers WHERE CustomerID = ?
The order in which you add SqlCeParameter objects to the SqlCeParameterCollection must correspond directly to the position of the question mark placeholder for the parameter.
Note If the parameters in the collection do not match the requirements of the query to be executed, an error may result.
Example
[Visual Basic, C#] The following example creates a SqlCeCommand and sets an array of SqlCeParameter objects.
[Visual Basic] Public Sub SqlCeCommandPrepare() Dim id As Integer = 20 Dim desc As String = "myFirstRegion" Dim conn As SqlCeConnection = New SqlCeConnection("Data Source = Northwind.sdf;") conn.Open() Dim command As SqlCeCommand = conn.CreateCommand() ' Create and prepare a SQL statement. command.CommandText = "INSERT INTO Region (RegionID, RegionDescription) VALUES (?, ?)" ' Note: Even though named parameterized queries are not supported, we still need ' to provide unique parameter names so that we can manipulate parameter collection; command.Parameters.Add("@id", id) command.Parameters.Add("@desc", desc) ' Calling Prepare after having set the Commandtext and parameters. command.Prepare() command.ExecuteNonQuery() ' Change parameter values and call ExecuteNonQuery. command.Parameters(0).Value = 21 command.Parameters(1).Value = "mySecondRegion" command.ExecuteNonQuery() End Sub [C#] public void SqlCeCommandPrepareEx() { int id = 20; string desc = "myFirstRegion" ; SqlCeConnection conn = new SqlCeConnection("Data Source = Northwind.sdf;"); conn.Open(); SqlCeCommand command = conn.CreateCommand(); // Create and prepare a SQL statement. command.CommandText = "INSERT INTO Region (RegionID, RegionDescription) VALUES (?, ?)"; // Note: Even though named parameterized queries are not supported, we still need // to provide unique parameter names so that we can manipulate parameter collection; command.Parameters.Add( "@id", id) ; command.Parameters.Add( "@desc", desc) ; // Calling Prepare after having set the Commandtext and parameters. command.Prepare() ; command.ExecuteNonQuery(); // Change parameter values and call ExecuteNonQuery again. command.Parameters[0].Value = 21; command.Parameters[1].Value = "mySecondRegion"; command.ExecuteNonQuery(); }
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button in the upper-left corner of the page.
Requirements
Platforms: .NET Compact Framework
.NET Framework Security:
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries From Partially Trusted Code
See Also
SqlCeCommand Class | SqlCeCommand Members | System.Data.SqlServerCe Namespace | SqlCeParameter
Syntax based on .NET Framework version 1.1.
Documentation version 1.1.1.