SqlCeCommand.CommandText Property

Gets or sets an SQL statement to execute at the data source.

Namespace: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (in system.data.sqlserverce.dll)

Syntax

'Declaration
Public Overrides Property CommandText As String
public override string CommandText { get; set; }
public:
virtual property String^ CommandText {
    String^ get () override;
    void set (String^ value) override;
}
/** @property */
public String get_CommandText ()

/** @property */
public void set_CommandText (String value)
public override function get CommandText () : String

public override function set CommandText (value : String)

Property Value

The SQL statement to execute or the name of the base table to open. The default value is an empty string.

Remarks

When the CommandType property is set to TableDirect, the CommandText property should be set to the name of the table to be accessed. TableDirect access is the fastest way to retrieve data from SQL Server Compact 3.5 SP1. You may be required to use escape character syntax if any of the tables named contain any special characters. All rows and columns of the named table or tables will be returned when you call one of the Execute methods.

You cannot set the Connection, CommandType, and CommandText properties if the current connection is performing an Execute or Fetch operation.

The .NET Compact Framework Data Provider for SQL Server Compact 3.5 SP1 supports named parameters for passing parameters to an SQL statement called by a SqlCeCommand when CommandType is set to Text. For example:

SELECT * FROM Customers WHERE CustomerID = @customerID

The Data Provider for SQL Server Compact 3.5 SP1 also does not support batch queries. Commands must follow the following form: 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 modify your queries to conform to this restriction.

Specify column names for INSERT queries when using RDA enabled replication. RDA tracked tables contain system-generated columns that will change the count of columns you may have expected for your query. If you do not specify column names and the number of columns in the INSERT statement is different from the number of columns in the table, the INSERT will fail.

Example

The following example creates a SqlCeCommand and sets the CommandText and other properties.

Dim cmd As SqlCeCommand = conn.CreateCommand()
cmd.CommandText = "SELECT * FROM Categories ORDER BY CategoryID"
cmd.CommandType = CommandType.Text
cmd.UpdatedRowSource = UpdateRowSource.Both
SqlCeCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM Categories ORDER BY CategoryID";
cmd.CommandType = CommandType.Text;
cmd.UpdatedRowSource = UpdateRowSource.Both;

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.

Platforms

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

See Also

Reference

SqlCeCommand Class
SqlCeCommand Members
System.Data.SqlServerCe Namespace
Connection
CommandType