Advertisement
Guest User

Untitled

a guest
Nov 21st, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. string ConnectionString = "server=localhost; password = 1234; database = DB ; user = Jack";
  2. MySqlConnection mConnection = new MySqlConnection(ConnectionString);
  3. mConnection.Open();
  4. int index = 1;
  5.  
  6.  
  7. for (int i = 0; i < 100000; i++)
  8. {
  9.  
  10. string insertPerson = "INSERT INTO myentities(Name) VALUES (@first_name);"
  11. + "INSERT INTO secondtable(Id, Name,myentities) VALUES (@ID, @city, LAST_INSERT_ID());";
  12. MySqlCommand command = new MySqlCommand(insertPerson, mConnection);
  13. command.Parameters.AddWithValue("@first_name", "Jack");
  14. command.Parameters.AddWithValue("@ID", i+1);
  15.  
  16. command.Parameters.AddWithValue("@city", "Frank");
  17.  
  18. command.ExecuteNonQuery();
  19. command.Parameters.Clear();
  20. }
  21.  
  22. public static void BulkToMySQL()
  23. {
  24. string ConnectionString = "server=192.168.1xxx";
  25. StringBuilder sCommand = new StringBuilder("INSERT INTO User (FirstName, LastName) VALUES ");
  26. using (MySqlConnection mConnection = new MySqlConnection(ConnectionString))
  27. {
  28. List<string> Rows = new List<string>();
  29. for (int i = 0; i < 100000; i++)
  30. {
  31. Rows.Add(string.Format("('{0}','{1}')", MySqlHelper.EscapeString("test"), MySqlHelper.EscapeString("test")));
  32. }
  33. sCommand.Append(string.Join(",", Rows));
  34. sCommand.Append(";");
  35. mConnection.Open();
  36. using (MySqlCommand myCmd = new MySqlCommand(sCommand.ToString(), mConnection))
  37. {
  38. myCmd.CommandType = CommandType.Text;
  39. myCmd.ExecuteNonQuery();
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement