MySqlCommand.ExecuteNonQuery Method

MySQL Connector/Net

MySqlCommandExecuteNonQuery Method
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.9.9
Syntax
public override int ExecuteNonQuery()
Public Overrides Function ExecuteNonQuery As Integer
public:
virtual int ExecuteNonQuery() override
abstract ExecuteNonQuery : unit -> int 
override ExecuteNonQuery : unit -> int 

Return Value

Type: Int32
Number of rows affected

Implements

IDbCommandExecuteNonQuery
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.
public void CreateMySqlCommand(string myExecuteQuery, MySqlConnection myConnection)
{
MySqlCommand myCommand = new MySqlCommand(myExecuteQuery, myConnection);
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
}
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

No code example is currently available or this language may not be supported.

No code example is currently available or this language may not be supported.

See Also