if (this.CheckBox1.Checked=true)
{
string strInsert;//插入数据表的标准的SQL语句
strInsert="update anli set timu1 = timu1 + 1 where id = 1";
//string strInsert;//插入数据表的标准的SQL语句
//strInsert="update anli set timu1 = timu1 + 1 where id = 1";
//如何插入?
//连接数据库
string strconn = "server=localhost;uid=sa;pwd=sa;database=vote";
SqlConnection cnn = new SqlConnection(strconn);
cnn.Open();
//声明命令对象并且初始化
SqlCommand cmd = new SqlCommand();
cmd.CommandText = strInsert;
cmd.CommandType = CommandType.Text;
cmd.Connection = cnn;
//初始化完成,直接执行命令对象,完成数据的插入工作台
try
{
cmd.ExecuteNonQuery();
//插入数据成功
//Response.Write("<script>alert('恭喜您投票成功!');window.location='Default2.aspx';</script>");
//Response.End();
}
catch (SqlException x)
{
Response.Write("<script>alert('投票失败!请重新选择,多谢配合');history.go(-1);</script>");
Response.End();
}
finally
{
cnn.Close();
}
}
&& if (this.CheckBox2.Checked = true)
{
string strInsert;//插入数据表的标准的SQL语句
strInsert = "update anli set timu2 = timu2 + 1 where id = 1";
//string strInsert;//插入数据表的标准的SQL语句
//strInsert="update anli set timu1 = timu1 + 1 where id = 1";
//如何插入?
//连接数据库
string strconn = "server=localhost;uid=sa;pwd=sa;database=vote";
SqlConnection cnn = new SqlConnection(strconn);
cnn.Open();
------解决方案--------------------
遍历CheckBox并且记录选中的个数,遍历结束的时候判断是否为6个,还有不明白你写的如何插入是什么意思?怎样执行sql语句还是?如果是,找一个例子好好看一下,还有不必要为每一个选中CheckBox都操作数据库,写一个就可以了。
------解决方案--------------------
把checkbox遍历一边,然后看下有几个被选中就行了
------解决方案--------------------
bool isValid = false;
isValid = CheckBoxList1.Items.Cast<ListItem>()