Executes a Transact-SQL statement against the connection and returns the number of rows affected.
[Visual Basic] Shared OverloadsPublic Function ExecuteNonQuery( _ ByVal connection As SqlConnection, _ ByVal commandText As String, _ ByVal commandType As CommandType _ ) As Integer [C#] public static int ExecuteNonQuery( SqlConnection connection, string commandText, CommandType commandType ); [C++] public: static int ExecuteNonQuery( SqlConnection* connection, String* commandText, CommandType commandType ); [JScript] public static function ExecuteNonQuery( SqlConnection connection, String commandText, CommandType commandType ): int;
The number of rows affected.
[C#, Visual Basic] The following example creates a SqlCommand and then executes it using ExecuteNonQuery. The example is passed a string that is a Transact-SQL statement (such as UPDATE, INSERT, or DELETE) and a string to use to connect to the data source.
[C#]SqlConnection connection = new SqlConnection("Server=127.0.0.1;Database=Northwind;Uid=sa;Pwd=;"); DatabaseUtility.ExecuteNonQuery(connection, "INSERT INTO Categories (CategoryName) VALUES ('New Category')", CommandType.Text);[Visual Basic]Dim connection As New SqlConnection("Server=127.0.0.1;Database=Northwind;Uid=sa;Pwd=;") DatabaseUtility.ExecuteNonQuery(connection, "INSERT INTO Categories (CategoryName) VALUES ('New Category')", CommandType.Text)
DatabaseUtility Class | Joel.Net Namespace | DatabaseUtility.ExecuteNonQuery Overload List