Execute Commands
What this page covers#
This page shows how to execute commands that do not return result sets.
The simple version#
Use ExecuteAsync() for inserts, updates, deletes, and similar commands.
var rowsAffected = await db.ExecuteAsync( "dbo.usp_User_UpdateDisplayName", new MooParams() .AddInt("@UserId", 1) .AddNVarChar("@DisplayName", "Ada Lovelace", 200));
The return value is the row count reported by SQL Server.
Raw SQL example#
var rowsAffected = await db.Sql.ExecuteAsync( "UPDATE [dbo].[tbl_User] SET [DisplayName] = @DisplayName WHERE [UserId] = @UserId;", new MooParams() .AddNVarChar("@DisplayName", "Ada Lovelace", 200) .AddInt("@UserId", 1));