Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 < 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();
- }
- 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<string> Rows = new List<string>();
- for (int i = 0; i < 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();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement