title: How to Insert to multi MYSQL tables C# fast?
body: <p>I am trying to insert some data into two MYSQL tables.
  the second table stores the first table row Id as a foreign key. 
  I have this code that works fine but it is super slow. what is the best/fastest way to make it faster?</p>
  
  <pre><code>string ConnectionString = "server=localhost; password = 1234; database = DB ; user = Jack";
          MySqlConnection mConnection = new MySqlConnection(ConnectionString);
          mConnection.Open();
          int index = 1;
  
  
          for (int i = 0; i &lt; 100000; i++)
          {
  
              string insertPerson = "INSERT INTO myentities(Name) VALUES (@first_name);"
                      + "INSERT INTO secondtable(Id, Name,myentities) VALUES (@ID, @city, LAST_INSERT_ID());";
              MySqlCommand command = new MySqlCommand(insertPerson, mConnection);
              command.Parameters.AddWithValue("@first_name", "Jack");
              command.Parameters.AddWithValue("@ID", i+1);
  
              command.Parameters.AddWithValue("@city", "Frank");
  
              command.ExecuteNonQuery();
              command.Parameters.Clear();
          }
  </code></pre>
  
  <p>I have found the following code on one of the StackoverFlow questions but it was inserting data to a single table only, not to multiple tables which are connected through a foreign key.
  This code is pretty fast, but I was not sure how I can make it work with multiple tables.</p>
  
  <pre><code>    public static void BulkToMySQL()
  {
      string ConnectionString = "server=192.168.1xxx";
      StringBuilder sCommand = new StringBuilder("INSERT INTO User (FirstName, LastName) VALUES ");           
      using (MySqlConnection mConnection = new MySqlConnection(ConnectionString))
      {
          List&lt;string&gt; Rows = new List&lt;string&gt;();
          for (int i = 0; i &lt; 100000; i++)
          {
              Rows.Add(string.Format("('{0}','{1}')", MySqlHelper.EscapeString("test"), MySqlHelper.EscapeString("test")));
          }
          sCommand.Append(string.Join(",", Rows));
          sCommand.Append(";");
          mConnection.Open();
          using (MySqlCommand myCmd = new MySqlCommand(sCommand.ToString(), mConnection))
          {
              myCmd.CommandType = CommandType.Text;
              myCmd.ExecuteNonQuery();
          }
      }
  }
  </code></pre>