Hi,
This is in continuation to Kythen's answer. Move out this code block from the loop.
string sql = "update table2 set type='expired' where id='" + id + "'";
using(SqlCommand cmd1 = new SqlCommand(sql, con))
{
cmd1.ExecuteNonQuery();
}
Instead just collect the ids in the loop and execute the query outside the loop.
StringBuilder sb=new StringBuilder();
sb.append(id); sb.append(",");
string sql=@"UPDATE table2 SET type='expired' WHERE id IN ("+sb.ToString()+")";
Then execute it using the nonquery. So you won't be chatty with the sql server.