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 7417941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:47:38+00:00 2026-05-29T07:47:38+00:00

This is my first post on here.. I’m writing a program in MVC3 that

  • 0

This is my first post on here..

I’m writing a program in MVC3 that has a WCF service which acts as the Data Access Layer. In my DAL, I have to do some sort of ‘batch’ inserts and updates.. particularly with orders for example.. let’s say one order has several items and could have several payment methods etc.. so when I insert a new order I’ll need to insert all items related to that order and so on..

Therefore, what I’m looking for is the better way and feasible method to be able to run several stored procedures, e.g one which will insert the order, another which will insert its items, etc..

The tables Order and Item are linked together with a third table called Order_Items, which will have (fk) order_id, (fk) item_id, qty, price..

I know I can run multiple commands by changing command text and and executing non query withing a transaction.. but I would like to run stored procedures instead of hardcoding text commands.. or I can run the procedures by making command text something like

cmd.CommandText = 'exec sp_insert_order @order_number @order_date ...'
cmd.ExecuteNonQuery();

and then loop the items say

foreach (string s in insert_items)
{
    cmd.CommandText = s;
    cmd.ExecuteNonQuery();
}

all this within a transaction and then do a commit.. but I don’t feel this is such a clean way of doing things.. can someone please share their opinion.

  • 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-29T07:47:39+00:00Added an answer on May 29, 2026 at 7:47 am

    If you’re using stored procedure, you should change the way you call them – I would recommend using this approach:

    // define your stored procedure name, and the type 
    cmd.CommandText = 'dbo.sp_insert_order';
    cmd.CommandType = CommandType.StoredProcedure;
    
    // define and fill your parameters
    cmd.Parameters.Add("@order_number", SqlDbType.Int).Value = order_nr;
    cmd.Parameters.Add("@order_date", SqlDbType.DateTime).Value = ......;
    
    cmd.ExecuteNonQuery();
    

    Basically, you’d have to do this for each stored procedure you want to call, and you could wrap all of those in a single transaction without any problems:

    using(SqlConnection connection = new SqlConnection("your-connection-string-here"))
    {
       SqlTransaction transaction = connection.BeginTransaction();
    
       try
       {
            // call all stored procuedures here - remember to assign the 
            // transaction to the SqlCommand!!
             ....
    
            transaction.Commit();
        }
        catch(Exception exc) 
        {
           transaction.Rollback();
        }        
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first post here! I'm trying to make a windows forms program
This is my first post here, and i should advise that my knowledge is
This is my first post here and I wanted to get some input from
This is my first post here. I have a problem. I need to take
this is my first post here on stackoverflow and am very impressed by the
Well, this is my first post here and really enjoying the site. I have
My first post here, so i hope this is the right area. I am
This is my first time here so I hope I post this question at
This is my first post here, therefore apologize for any blunders. I'm developing a
This is my first post here after many visits. Hello! I am trying to

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.