Which way is preferred?
SqlCommand = new SqlCommand(query);
command.Parameters.Add("@Foo");
command.Parameters[0].Value = Foo;
command.Parameters.Add("@Bar");
command.Parameters[1].Value = Bar;
// or
command.Parameters.Add("@Foo");
command.Parameters.Add("@Bar");
command.Parameters["@Foo"].Value = Foo;
command.Parameters["@Bar"].Value = Bar;
Two other options:
command.Parameters.AddWithValue("@Foo", Foo);
command.Parameters.Add("@Foo").Value = Foo;
Additionally, I don't think the speed difference between any of them would be enough that you should choose based on it; Pick the one that is the most readable to you and your team.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With