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

The Archive Base Latest Questions

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

I want to execute several inserts at the smame batch to speed up the

  • 0

I want to execute several inserts at the smame batch to speed up the program.
Is it possible to do the following?

Insert Into Table1 (a) Values (@a);
Insert Into Table2 (b) Values (@b);
Insert Into Table3 (c) Values (@c);

and if it’s possible then how should I pass the parameters to the SQL Parameters?

Basically I want to do something like this example but for Insert instead of Select

  • 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-12T18:57:27+00:00Added an answer on May 12, 2026 at 6:57 pm

    Another example:

    var sql = StringBuilder();
    
    sql.Append "Insert Table1(a)"
    sql.AppendFormat "\nSelect @a"
    sql.AppendFormat "\nUnion All Select @b"
    sql.AppendFormat "\nUnion All Select @b"
    sql.AppendFormat "\nUnion All Select @c"
    ...
    
    // Set your paramters values
    var cmd = new SqlCommand( sql.ToString() );
    SqlCommand.Parameters.Add(new SqlParameter("@b", aValue));
    SqlCommand.Parameters.Add(new SqlParameter("@b", bValue));
    SqlCommand.Parameters.Add(new SqlParameter("@c", cValue));
    ...
    
    cmd.ExecuteNonQuery();
    

    The line breaks are not necessary. They are only there so the output is nicely formatted. If you put your values into a hashtable, you could even do it in a loop like so:

    var values = new Hashtable();
    values.Add("a", avalue);
    values.Add("b", bvalue);
    values.Add("c", cvalue);
    ...
    
    
    var sql = StringBuilder();
    var cmd = new SqlCommand();
    
    foreach( var value in values )
    {
        if (sql.Length == 0)
        {
            sql.Append "Insert Table1(columnName)"
            sql.AppendFormat "\nSelect @" + value.Key   
            cmd.Parameters.Add(new SqlParameter("@" + value.Key, value.Value));
        }
        else
        {
            sql.AppendFormat "\nUnion All Select @" + value.Key
            cmd.Parameters.Add(new SqlParameter("@" + value.Key, value.Value));
        }
    }
    
    cmd.CommandText = sql.ToString()
    cmd.ExecuteNonQuery();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make an application to execute several instructions to pass the following
Sometimes I find myself in the situation where I want to execute several sequential
I want to connect and execute one (or sometimes several) SQL statements, and NOT
I have a function that I want to execute several times for different DOM
I want to execute several commands by PHP, //DISPLAY setting $command1 = 'export DISPLAY=:1';
I have several WCF services and I want to execute methods in them at
I have several transactions to insert form data into oracle table. if (InsertQuarterly() ==
The question is very easy, I want to execute several php files every N
I want to execute several select sql queries through 1 connection to the database
I'm writing program in C++ (for XAMPP communication) and I want to execute command

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.