MySQL Connector/Net |
MySqlCommand..::.ExecuteNonQuery Method |
MySqlCommand Class Example See Also Send Feedback |
Executes a SQL statement against the connection and returns the number of rows affected.
Namespace:
MySql.Data.MySqlClient
Assembly:
MySql.Data (in MySql.Data.dll) Version: 6.2.2.0
Syntax
C# |
---|
public override int ExecuteNonQuery() |
Visual Basic (Declaration) |
---|
Public Overrides Function ExecuteNonQuery As Integer |
Visual C++ |
---|
public: virtual int ExecuteNonQuery() override |
Return Value
Number of rows affectedImplements
IDbCommand..::.ExecuteNonQuery()()()Remarks
You can use ExecuteNonQuery to perform any type of database operation,
however any resultsets returned will not be available. Any output parameters
used in calling a stored procedure will be populated with data and can be
retrieved after execution is complete.
For UPDATE, INSERT, and DELETE statements, the return value is the number
of rows affected by the command. For all other types of statements, the return
value is -1.
Examples
The following example creates a MySqlCommand and then
executes it using ExecuteNonQuery. The example is passed a string that is a
SQL statement (such as UPDATE, INSERT, or DELETE) and a string to use to
connect to the data source.
CopyVB.NET
Public Sub CreateMySqlCommand(myExecuteQuery As String, myConnection As MySqlConnection) Dim myCommand As New MySqlCommand(myExecuteQuery, myConnection) myCommand.Connection.Open() myCommand.ExecuteNonQuery() myConnection.Close() End Sub
CopyC#
public void CreateMySqlCommand(string myExecuteQuery, MySqlConnection myConnection) { MySqlCommand myCommand = new MySqlCommand(myExecuteQuery, myConnection); myCommand.Connection.Open(); myCommand.ExecuteNonQuery(); myConnection.Close(); }