I would suggest following change to start with:
StringBuilder sb = new StringBuilder();
for (int i = 1; ++i <= 50000; )
{
sb.Append(string.Format("insert into table1(id,memberid,nameid,id1,id2,createdby,createdon) value('{0}','{1}','{2}','{3}','{4}','dss',now());", 0, 12, 1, i, 1));
}
MySqlCommand cmd = new MySqlCommand(sb.ToString(), con, tran);
cmd.ExecuteNonQuery();
The above code has not optimized the loop itself but really saved up a lot of memory and resources by utilizing the
stringbuilder
and removing on the fly string concatenations. Since you are running the loop 50000 times and the string itself if quite lengthy, you will see a VERY BIG performance gain.