I'm trying to update a SQL Server database and have a list of strings which are seat numbers
string strQuery = ("Update tblTransactionItems set selected = 'T' Where SeatNumber = @SeatNumber");
using (SqlCommand cmd = new SqlCommand(strQuery, con)) {
con.Open();
foreach (var item in list) {
string test = item.ToString();
test = test.Replace('"', ' ').Trim();
cmd.Parameters.AddWithValue("@SeatNumber", test);
cmd.ExecuteNonQuery();
}
}
It keeps saying that the variable @SeatNumber has been declared and only the first item in the list is updated. Any ways on how to approach this?
Update :
I just placed the foreach loop outside the using and it works.