It is not working, it is running once, then it is failling but you are catching Exception
but not doing anything with it. The problem with your code is that you are adding duplicate parameters. You should clear them after each loop:
foreach (KeyValuePair<string, int> pair in url)
{
mySqlCommand.Parameters.Clear();
mySqlCommand.Parameters.Add(
new SqlParameter("@uniqueKeyWords", pair.Key));
mySqlCommand.Parameters.Add(
new SqlParameter("@counts", pair.Value));
mySqlCommand.CommandType = CommandType.StoredProcedure;
mySqlCommand.Connection.Open();
count = mySqlCommand.ExecuteNonQuery();
mySqlCommand.Connection.Close();
}
1
solved Why it is a good practice to right try catch in foreach loop? [closed]