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

  • Home
  • SEARCH
  • 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 8682933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:54:23+00:00 2026-06-12T21:54:23+00:00

In my code I am repeating code blocks like this all the time: var

  • 0

In my code I am repeating code blocks like this all the time:

var returnData = MyDb.ExecuteDataSet(
    MyDb.GetStoredProcCommand("MyTable_Insert", columnOne, columnTwo, columnThree),
    transaction
);

var returnId = (int)returnData.Tables[0].Rows[0]["INSERTED_ID"];

This seems to me to be a fairly large block of code to be repeating so many times, but I can’t work out how to generalise it into a method because the number of arguments is different to each stored procedure.

The obvious solution (to me) is to pass my parameters through to the function in an array and then expand them to call GetStoredProcCommand, but I can’t find a way to do this:

private int CallStoredProcedure(string procName, List<dynamic> parameterValues) {
    ..
    MyDb.GetStoredProcCommand(procName, expand parameterValues);
    // ERROR: Obviously "expand" doesn't exist
    ..
}

I could use the longer-winded way passing parameters using AddInParameter, but then I would need to pass type information along with the parameter values:

private int CallStoredProcedure(string procName, IDictionary<DbType, IDictionary<string, string>> paramsKeyValuesByType) {
    ..
    MyDb.AddInParameter(myProcCommand, param.Value.Key, param.Key, param.Value.Value);
    ..
}

But then I’d have to construct the IDictionary object before calling the method which would be even more long-winded than how I was originally calling the procedure.

Can anyone think of an elegant solution to this?

  • 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-06-12T21:54:24+00:00Added an answer on June 12, 2026 at 9:54 pm

    You can use the params keyword:

    private int CallStoredProcedure(string procName, params object[] parameterValues) {
        ..
        MyDb.GetStoredProcCommand(procName, parameterValues);
        ..
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would I write this code without all the duplication // I have a
It turned out that this conditional block keeps on repeating itself in my code.
I have a code that sets a new repeating alarm (on production I'll use
function urllinks(str){ return str.replace(/\b((http|https):\/\/\S+)/g,'<a href=$1 target=_blank>$1</a>'); } This code is replacing only http and
If using code like the following to impersonate another user, [DllImport(advapi32.dll, SetLastError = true)]
I have this replace regex (it's taken from the phpbb source code). $match =
This feels like a newbie issue, but I can't seem to figure it out.
In my mind I have a query that goes something like this: $sort =
(I have a workaround for this problem, but it's not the first time I've
I have a try-catch block that iterates over a set of records like this:

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.