Executes a Transact-SQL statement against the connection and returns the number of rows affected.
[Visual Basic] Shared OverloadsPublic Function ExecuteNonQuery( _ ByVal database As String, _ ByVal commandText As String, _ ByVal commandType As CommandType _ ) As Integer [C#] public static int ExecuteNonQuery( string database, string commandText, CommandType commandType ); [C++] public: static int ExecuteNonQuery( String* database, String* commandText, CommandType commandType ); [JScript] public static function ExecuteNonQuery( String database, 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#]DatabaseUtility.Connection = new SqlConnection("Server=127.0.0.1;Database=Northwind;Uid=sa;Pwd=;"); DatabaseUtility.ExecuteNonQuery("Northwind", "INSERT INTO Categories (CategoryName) VALUES ('New Category')", CommandType.Text);[Visual Basic]DatabaseUtility.Connection = New SqlConnection("Server=127.0.0.1;Database=Northwind;Uid=sa;Pwd=;") DatabaseUtility.ExecuteNonQuery("Northwind", "INSERT INTO Categories (CategoryName) VALUES ('New Category')", CommandType.Text)
DatabaseUtility Class | Joel.Net Namespace | DatabaseUtility.ExecuteNonQuery Overload List