Please tell me how to make the following code faster (I mean the WriteToBase method).
class MyClass { public int a; public int b; public int c; } void main() { List<MyClass> mc=new List<MyClass>(); mc.Add(new MyClass()); //example mc.Add(new MyClass()); WriteToBase(mc); } void WriteToBase(List<MyClass> mc) { //Create Connection string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)"; SqlCommand cmdIns = new SqlCommand(sqlIns, Connection); for(int i=0;i<mc.Count;i++) { cmdIns.Parameters.Add("@name", mc[i].a); cmdIns.Parameters.Add("@information", mc[i].b); cmdIns.Parameters.Add("@other", mc[i].c); cmdIns.ExecuteNonQuery(); } } }
Any ideas?
source share