Can you try this once? No major code change. just trying to initialize command object in each iteration of the loop.
protected void btncast_Click(object sender, EventArgs e)
{
StringBuilder strSql = new StringBuilder(string.Empty);
SqlConnection con = new SqlConnection(strConnection);
SqlCommand cmd;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chkselect = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("chkselect");
if (chkselect != null)
{
if (chkselect.Checked)
{
string strID = GridView1.Rows[i].Cells[0].Text;
try
{
cmd = new SqlCommand();
const string strUpdate = "Update Candidate_list set total_counts = total_counts+1 WHERE pic_id = @pic_id";
cmd.CommandType = CommandType.Text;
cmd.CommandText = strUpdate.ToString();
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@pic_id", strID);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
}
catch (SqlException ex)
{
string errorMsg = "Error in Updation";
errorMsg += ex.Message;
throw new Exception(errorMsg);
}
finally
{
con.Close();
Response.Redirect("~/Voting.aspx/");
}
}
}
}
}
}