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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:18:46+00:00 2026-06-12T04:18:46+00:00

Mysql give example how insert rows with prepare statement and .NET: http://dev.mysql.com/doc/refman/5.5/en/connector-net-programming-prepared.html Its looks

  • 0

Mysql give example how insert rows with prepare statement and .NET:
http://dev.mysql.com/doc/refman/5.5/en/connector-net-programming-prepared.html

Its looks that its works like that,because in the end of each iteration call to:cmd.ExecuteNonQuery():

INSERT INTO VALUES()...;INSERT INTO VALUES()...;INSERT INTO VALUES()...;

Can it done with use of prepare statement like that:

INSERT INTO all values...

More explanations::


The code in mysql example (cmd.ExecuteNonQuery() in each iteration):

MySql.Data.MySqlClient.MySqlConnection conn;
MySql.Data.MySqlClient.MySqlCommand cmd;

conn = new MySql.Data.MySqlClient.MySqlConnection();
cmd = new MySql.Data.MySqlClient.MySqlCommand();

conn.ConnectionString = strConnection;

try
{
    conn.Open();
    cmd.Connection = conn;

    cmd.CommandText = "INSERT INTO myTable VALUES(NULL, @number, @text)";
    cmd.Prepare();

    cmd.Parameters.AddWithValue("@number", 1);
    cmd.Parameters.AddWithValue("@text", "One");

    for (int i=1; i <= 1000; i++)
    {
        cmd.Parameters["@number"].Value = i;
        cmd.Parameters["@text"].Value = "A string value";

        cmd.ExecuteNonQuery();
    }
}

*The code that i want to have like that(cmd.ExecuteNonQuery(); after all iterations): *

MySql.Data.MySqlClient.MySqlConnection conn;
MySql.Data.MySqlClient.MySqlCommand cmd;

conn = new MySql.Data.MySqlClient.MySqlConnection();
cmd = new MySql.Data.MySqlClient.MySqlCommand();

conn.ConnectionString = strConnection;

try
{
    conn.Open();
    cmd.Connection = conn;

    cmd.CommandText = "INSERT INTO myTable VALUES(NULL, @number, @text)";
    cmd.Prepare();

    cmd.Parameters.AddWithValue("@number", 1);
    cmd.Parameters.AddWithValue("@text", "One");

    for (int i=1; i <= 1000; i++)
    {
        cmd.Parameters["@number"].Value = i;
        cmd.Parameters["@text"].Value = "A string value";


    }
    cmd.ExecuteNonQuery();
}
  • 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-12T04:18:48+00:00Added an answer on June 12, 2026 at 4:18 am

    Try this:

    using (var connection = new MySqlConnection("your connection string"))
    {
        connection.Open();
        // first we'll build our query string. Something like this :
        // INSERT INTO myTable VALUES (NULL, @number0, @text0), (NULL, @number1, @text1)...; 
        StringBuilder queryBuilder = new StringBuilder("INSERT INTO myTable VALUES ");
        for (int i = 0; i < 10; i++)
        {
            queryBuilder.AppendFormat("(NULL,@number{0},@text{0}),", i);
            //once we're done looping we remove the last ',' and replace it with a ';'
            if (i == 9)
            {
                queryBuilder.Replace(',', ';', queryBuilder.Length - 1, 1);
            }
        }
    
    
        MySqlCommand command = new MySqlCommand(queryBuilder.ToString(), connection);
        //assign each parameter its value
        for (int i = 0; i < 10; i++)
        {
            command.Parameters.AddWithValue("@number" + i, i);
            command.Parameters.AddWithValue("@text" + i, "textValue");
        }
    
        command.ExecuteNonQuery();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Mysql supports prepared statements in this way: http://dev.mysql.com/doc/refman/5.0/en/sql-syntax-prepared-statements.html Is there a support for it
My problem is, that MySQL orders characters before numbers. To give a quick example,
I am using MySql (and PHP). It's best if I give an example: I
Why does the MySQL query below give error 1066 (Not unique table/alias: 'customer') ?
The code I used doesn't give me any MySQL errors (which is good) Except
I install the MySQL in my EC2 instance, then I give to root a
I have a SQL query where I want to insert multiple rows in single
Anyone have any SQL-fu (can be MySQL-specific) that will give me the indexes of
I am trying to insert a mysql query itself into a table field(Executing a
I found this: http://en.wikipedia.org/wiki/MySQL_DataController which lead me to this: https://launchpad.net/datacontroller It looks like a

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.