I make a continuous selection every 10 seconds, so I thought that I would do some premature optimizations and keep creating cmd and paramater objects in everyloop
if I do it in one way
public void FirstSelect() {
this.cmdSelectData = new SqlCommand(SQL_SELECT_DATA, conn);
this.paramBranchId = new SqlParameter("@branch_id", 1);
this.cmdSelectData.Parameters.Add(paramBranchId);
}
and then this in another method
public void SecondSelect() {
this.paramBranchId.Value = 2;
}
will work as expected, one select using branch 1, one select using branch 2 or I need
this.cmdSelectData.Parameters.Clear();
ths.cmdSelectData.Parameters.Add(new SqlParameter( // for branch 2)
}
source
share