I have a list of ints called idList. I'd like to update a the TaskState in Tasks table for each id in that idList. This is how my code looks now :
using (SqlConnection dataconnection = new SqlConnection(DB))
{
SqlCommand sqlCommandDelete = new SqlCommand()
{
Connection = dataconnection
};
dataconnection.Open();
foreach (var id in idList)
{
qlCommandDelete.CommandText = $"UPDATE Tasks SET TaskState = 2 WHERE TaskID = {id}";
sqlCommandDelete.ExecuteNonQuery();
}
}
Now the problem is that I execute each time the loop fires. Is there maybe a way of connecting all the TaskIDs and executing only once?