Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6795435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:20:41+00:00 2026-05-26T18:20:41+00:00

The system I am currently working on uses Stored Procedures for all data access.

  • 0

The system I am currently working on uses Stored Procedures for all data access. I’m looking into Dapper at the moment (so far it looks great) but I was wondering if I can use a DynamicParameters object created using a Template but make one of the parameters an output param. For example:

SP:

CREATE PROCEDURE InsertPerson
  @ID int Output,
  @Name varchar(100),
  @DOB DateTime2
AS
--INSERT STATEMENT

SET @ID = SCOPE_IDENTITY()

POCO:

internal class Person
{
  public int ID { get; set; }
  public string Name { get; set; }
  public DateTime DOB { get; set; }
}

Code:

var procParams = new DynamicParameters(person);
connection.Execute("InsertPerson", procParams, commandType: CommandType.StoredProcedure);

// This is where i'm having the issue, can it be done?
person.ID = procParams.Get<int>("ID");

Current I receive an error because the key was not found. Is there a way to get the ID output parameter without manually setting up all of the stored procs parameters?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:20:42+00:00Added an answer on May 26, 2026 at 6:20 pm

    With a quick tweak, Add now replaces the value from a template, allowing:

    public void TestProcWithOutParameter()
    {
        connection.Execute(
            @"CREATE PROCEDURE #TestProcWithOutParameter
    @ID int output,
    @Foo varchar(100),
    @Bar int
    AS
    SET @ID = @Bar + LEN(@Foo)");
        var obj = new
        { // this could be a Person instance etc
            ID = 0,
            Foo = "abc",
            Bar = 4
        };
        var args = new DynamicParameters(obj);
        args.Add("ID", 0, direction: ParameterDirection.Output);
        connection.Execute("#TestProcWithOutParameter", args,
                     commandType: CommandType.StoredProcedure);
        args.Get<int>("ID").IsEqualTo(7);
    }
    

    Is that close enough? You can also use ParameterDirection.ReturnValue, of either a pre-existing value or a new value. Note it does not update directly back into the original template; the value must be fetched from the DynamicParameters instance (as shown).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a project that hooks into various system calls and writes
I am currently working on a pyramid system that uses sqlalchemy. This system will
I'm working on a login system for a website that currently uses Apache's prompt
I am currently working on exposing data from legacy system over the web. I
The system I am currently working on requires some role-based security, which is well
In a system I am currently working on, there is one process that loads
I'm currently working on a ticketing system which allows our users to submit tickets
I'm currently working on an asp.net-mvc content management system. It would be incredibly useful
I am working on a system on which currently linux kernel and microwindows windowing
A little backstory, currently I'm working on implementing a triangle rendering system in Expression2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.