SqlCeCommand.ExecuteNonQuery Method
Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.
Executes an SQL statement against the SqlCeConnection and returns the number of rows affected.
[Visual Basic] Public Overridable Function ExecuteNonQuery() As Integer Implements _ IDbCommand.ExecuteNonQuery [C#] public virtual int ExecuteNonQuery(); [C++] public: virtual int ExecuteNonQuery(); [JScript] public function ExecuteNonQuery() : int;
Return Value
The number of rows affected.
Implements
Exceptions
Exception Type | Condition |
---|---|
InvalidOperationException | The connection does not exist.
Or The connection is not open. OrCannot execute a command within a transaction context that differs from the context in which the connection was originally enlisted. |
Remarks
You can use ExecuteNonQuery to perform catalog operations. For example, you can use it to query the structure of a database or create database objects, such as tables. You also can use ExecuteNonQuery to change the data in a database without using a DataSet by executing UPDATE, INSERT, or DELETE statements.
For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. For all other DML statements, the return value is -1.
For DDL statements, such as CREATE TABLE or ALTER TABLE, the return value is 0.
Note This differs from the behavior of System.Data.SqlClient.
Example
[Visual Basic, C#] The following example creates a SqlCeCommand and then executes it by using ExecuteNonQuery. The example is passed a string that is an SQL statement (such as UPDATE, INSERT, or DELETE) and a string for connecting to the data source.
[Visual Basic] Public Sub CreateMySqlCeCommand(myExecuteQuery As String, myConnection As SqlCeConnection) Dim myCommand As New SqlCeCommand(myExecuteQuery, myConnection) myCommand.Connection.Open() myCommand.ExecuteNonQuery() myConnection.Close() End Sub [C#] public void CreateMySqlCeCommand(string myExecuteQuery, SqlCeConnection myConnection) { SqlCeCommand myCommand = new SqlCeCommand(myExecuteQuery, myConnection); myCommand.Connection.Open(); myCommand.ExecuteNonQuery(); myConnection.Close(); }
[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
Syntax based on .NET Framework version 1.1.
Documentation version 1.1.1.