如何将复选框的值存储在数据库中? [英] How can store checked box values in database?

查看:74
本文介绍了如何将复选框的值存储在数据库中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在.net Windows应用程序中创建一个表单.我有一个表,其中的列名为Name,Amount和Status.并且在前端,我分别使用了两个文本框作为Name和Amount列.并选中了两个复选框命名为已付款而未付款.

Hi,
I am creating a form in .net windows application.And I have a table with the columns named as Name,Amount and Status.And In my front end, i have use two text boxes for Name and Amount columns respectively.And two checked boxes named as paid and not paid.

private void button3_Click(object sender, EventArgs e)
{
   con.Open();
   SqlCommand cmd = new SqlCommand("insert into tablename (name,id) values('"+txtName.Text+"','"+txtId.Text+"')",con);
           cmd.ExecuteNonQuery();
           con.Close();
   }


通过此代码,我可以在相应的列中保存名称和ID.但是在状态列中,我应该存储复选框的一个值(已付款或未付款).为此,请给我发送代码.

谢谢
Viswanathan.M


By this code, i can save Name and ID in that corresponding columns.But in Status column, i should store either one value of checked box(either paid or not paid). For this kindly send me coding.

Thanks
Viswanathan.M

推荐答案

首先,应在表中将status列定义为boolean.
其次,将复选框值转换为true或false,然后将该值存储到表中.

您查询的内容类似于
First, the status column should be defined as boolean in the table.
Second, convert the checkbox value to true or false and then store that value into the table.

You query would be something like
insert into tablename (name,id,status) <br />
values<br />
(txtname,text,txtId.text, chkBox.checked)<br />
<br />


这篇关于如何将复选框的值存储在数据库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆