我想将复选框的值插入数据库。
但是在数据库中,该列为空。
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=NAWAF;Initial Catalog=waterreport;Integrated Security=True");
con.Open();
if (checkBox1.CheckState == CheckState.Checked)
{
string chkek = "finish";
}
SqlCommand tump;
SqlCommand orugg;
string tmp = " UPDATE reportonetmp set finish_repair_date='" + textBox1.Text + "', finish_repair_hour='" + textBox2.Text + "', ca_of_problem='" + comboBox1.Text + "', line_type='" + comboBox2.Text + "', situation='" + textBox3.Text + "', diameter_of_pipes ='" + comboBox3.Text + "', timenoww3 ='" + label7.Text + "' WHERE no like '" + label13.Text + "'";
tump = new SqlCommand(tmp, con);
tump.ExecuteNonQuery();
string org = " UPDATE reportone set finish_repair_date='" + textBox1.Text + "', finish_repair_hour='" + textBox2.Text + "', ca_of_problem='" + comboBox1.Text + "', line_type='" + comboBox2.Text + "', situation='" + textBox3.Text + "', diameter_of_pipes ='" + comboBox3.Text + "', timenoww3 ='" + label7.Text + "',checkk ='" + chkek + "' WHERE no like '" + label13.Text + "'";
orugg = new SqlCommand(org, con);
orugg.ExecuteNonQuery();
con.Close();
}
答案 0 :(得分:0)
除了其他问题(比如有非参数化查询),您确定您的数据库列已被调用' checkk'?
如果这是正确的,我会将该数据库列转换为第一位(如果您正在使用SQL Server)或布尔值并将其更新为这样,而不是使用字符串变量:
"',checkk ='" + checkBox1.Checked
答案 1 :(得分:-1)
对aspx页面中的复选框控件进行oncheckchanged,如果选中则表示将值设置为1 else 0(如果条件在checkedchanged事件中,则放置如此简单)。如果值1表示复选框ID,则可以从数据库中获取相同方式。像这样检查足够