Represents an SQL statement to execute against a data source.
For a list of all members of this type, see SqlCeCommand Members.
System.Object
System.MarshalByRefObject
System.Data.SqlServerCe.SqlCeCommand
[Visual Basic] NotInheritable Public Class SqlCeCommand Inherits MarshalByRefObject Implements ICloneable, IDbCommand, IDisposable [C#] public sealed class SqlCeCommand : MarshalByRefObject, ICloneable, IDbCommand, IDisposable [C++] public __gc __sealed class SqlCeCommand : public MarshalByRefObject, ICloneable, IDbCommand, IDisposable [JScript] public class SqlCeCommand extends MarshalByRefObject implements ICloneable, IDbCommand, IDisposable
Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.
When an instance of SqlCeCommand is created, the read/write properties are set to their initial values. For a list of these values, see the SqlCeCommand constructor.
SqlCeCommand features the following methods that execute commands at a data source:
| Item | Description |
|---|---|
| ExecuteReader | Executes commands that return rows. |
| ExecuteNonQuery | Executes SQL commands such as INSERT, DELETE, and UPDATE statements. |
| ExecuteScalar | Retrieves a single value (for example, an aggregate value) from a database. |
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 to the position of the question mark placeholder for the parameter.
The data provider for SQL Server CE also does not support batched queries. Commands must be in the form of Select * from Customers and not Select * from Customers; Select *
from Orders;. If you are using code generated for System.Data.SqlClient, you may have to alter your queries to conform to this restriction.
Although SQL Server CE only supports one connection at a time, multiple commands can share the same connection. This means that it is possible to have multiple instances of SqlCeDataReader on the same connection. This behavior differs from that of System.Data.SqlClient.
If a fatal SqlCeException is generated by the method executing a SqlCeCommand, the SqlCeConnection may be closed. You can reopen the connection and continue.
[Visual Basic, C#] The following example uses SqlCeCommand, along with SqlCeConnection, to select rows from a database.
[Visual Basic] Public Sub CreateMySqlCeCommand() Dim mySelectQuery As String = "SELECT * FROM Categories ORDER BY CategoryID" Dim myConnectString As String = "Data Source = Northwind.sdf; Password = <password>;" Dim myConnection As New SqlCeConnection(myConnectString) Dim myCommand As New SqlCeCommand(mySelectQuery, myConnection) myCommand.CommandType = CommandType.Text End Sub 'CreateMySqlCommand [C#] public void CreateMySqlCeCommand() { string mySelectQuery = "SELECT * FROM Categories ORDER BY CategoryID"; string myConnectString = "Data Source = Northwind.sdf; Password = <password>; "; SqlCeConnection myConnection = new SqlCeConnection(myConnectString); SqlCeCommand myCommand = new SqlCeCommand(mySelectQuery,myConnection); myCommand.CommandType = CommandType.Text; }
[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.
Namespace: System.Data.SqlServerCe
Platforms: .NET Compact Framework - Windows CE .NET
Assembly: System.Data.Sqlserverce (in System.Data.Sqlserverce.dll)
SqlCeCommand Members | System.Data.SqlServerCe Namespace | SqlCeDataAdapter | SqlCeConnection