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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:40:14+00:00 2026-05-18T07:40:14+00:00

Working with MYSQL in C#: I have a collection of parameterized IDbCommands I would

  • 0

Working with MYSQL in C#:

I have a collection of parameterized IDbCommands I would like to execute. The are a mixture of updates, inserts, and deletes, right now I am doing:


using (IDbConnection connection = Connecter.CreateConnection())
{
   foreach(IDBCommand command in m_commands)
   {
     command.Connection = connection;
     command.ExecuteNonQuery();
   }
}

The commands make heavy use of parameters so I can’t just combine the command texts of each command together. The performance is pretty terrible, and I know there has to be a better way.

Using the MYSql Bulk update took would be acceptable but it isn’t clear to me how to translate the parameter values into the file without risking SQL injection attacks.

Anyone have any suggestions?

(I have tied putting all the commands inside of a transaction which helps some but not enough)

  • 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-18T07:40:15+00:00Added an answer on May 18, 2026 at 7:40 am

    If multiple inserts/updates/deletes are to be applied to the same table(s), consider using a MySqlDataAdapter/DataTable combination to batch together like statements. Setting the MySqlDataAdapter’s UpdateBatchSize property will enable/disable batch processing support. Thus, inserts/updates/deletes on the same table can be sent to the DB in a single trip.

    I have done this will the OracleDataAdapter and SqlDataAdapter with significant performance gains. MySqlDataAdapter appears to implement basic batching as well (haven’t actually tested it though).

    One suggestion would be to create your own wrapper class that hides the underlying DbDataAdapter/DataTable classes in some form of DbCommandBatch class. This class can then build up the required DataTable backing from an IDbCommand template and ultimately group together like commands if desired.

    public interface IDbBatchCommandFactory
    {
      IDbCommandBatch Create(IDbCommand templateCommand);
    }
    

    So the Create method could actually build up the required DataTable from a template command if desired (may make life easier depending on what code you already have) by iterating over the existing parameter collection. This could then create a class that implements an interface something like:

    public interface IDbBatchCommand : IDisposable
    {
      void AddToBatch(ParameterCollection parameters);
      void ExecuteBatch(IDbTransaction transaction);
    }
    

    If this is on the right track for what you need I can provide sample code. If each command is distinct from one another (i.e., always different tables etc), then this will provide no value.

    Note: In a perfect world, classes like SqlCommandSet etc would be publically available to avoid having to do this wonkiness.

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

Sidebar

Related Questions

I'm working with PDO connection for mysql and I'd like to have some opinion
Any idea why the following code is not working mysql credentials are correct, have
I'm working on building a tree structure in MySQL and have been experimenting with
I am working on a filter functionality using ajax/jquery and php/mysql.I have two sets
I have working website in PHP with a MySQL backend which has several tables
I have been working on on an AJAX chat application using php, mysql. It's
I have a java program that connects to a MySql database and it's working
I am working on PHP and database MySQL. I have two tables in SQL
My team working on a php/MySQL website for a school project. I have a
Working on an AJAX website (HTML,CSS,JavaScript, AJAX, PHP, MySQL). I have multiple javascript functions

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.