Docs / Use Output Parameters

Use Output Parameters

What this page covers#

This page shows how to use output parameters with MooParams.

Example#

</> C#
using System.Data;

var parameters = new MooParams()
    .AddInt("@UserId", 42)
    .AddInt("@RowsAffected", null, ParameterDirection.Output)
    .AddNVarChar("@StatusMessage", null, 200, ParameterDirection.Output);

await db.ExecuteAsync("dbo.usp_User_Update", parameters);

var rowsAffected = parameters.GetInt("@RowsAffected");
var statusMessage = parameters.GetNullableString("@StatusMessage");

Key idea#

You add the parameter before execution, then read its value back from the same MooParams instance afterwards.

Notes#

  • use typed getters where possible
  • GetNullable... methods return null for DBNull
  • getters throw if the value cannot be read as the requested type