I have about 65 textbox fields in my ASP.NET form.
Instead of adding all parameters to SqlCommand
one by one, I want to do like this.
using (SqlCommand com = new SqlCommand(query, con))
{
string[] fields = { "EmployeeID", "EmployeeNumber", "FirstName", "MiddleName", "LastName" };
foreach (string fld in fields)
{
TextBox tb = (TextBox)Page.FindControl(fld);
com.Parameters.AddWithValue("@" + fld, tb.Text );
}
}
Is it a good idea to use FindControl
method when considering performance for this type of scenario.