SqlConnection conn = new SqlConnection("server=(local);database=SimpleVote;uid=sa;pwd=");
conn.Open();
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (CheckBoxList1.Items[i].Selected){
SqlCommand add = new SqlCommand("update VoteItem set ItemCount=ItemCount+1", conn);
add.ExecuteNonQuery(); }
}
C# checkboxlist 写入数据库
最新推荐文章于 2026-08-04 14:12:34 发布
本文介绍了一个使用C#实现的投票系统中更新投票项计数的代码片段。通过遍历CheckBoxList并检查每个项是否被选中,如果选中则通过SqlCommand对象更新对应的数据库记录,增加投票数量。

419

被折叠的 条评论
为什么被折叠?



