Can anyone tell me the following 2 ways of inserting record creates better performance?
Case 1
SqlCommand cmd = new SqlCommand();
for (int i = 0; i < 10000; i++)
{
cmd = new SqlCommand("insert into test(id, name) value('" + i + "', '" + i + "')");
cmd.ExecuteNonQuery();
}
Case 2
string sql = null;
for (int i = 0; i < 10000; i++)
{
sql += "insert into test(id, name) value('" + i + "', '" + i + "')";
}
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
SqlCommand
instances and executing them one by one is just as fast as creating a single instance and executing it just once??? – Myogenic