大家好,问个简单问题 this.checkBox1.Checked这个是个BOOL类型的我数据字段是bit我SQL语句怎么存储她呢strsll = "insert into info(life) values('" + this.checkBox1.Checked+ "')";这样写,无法运行请问大家,我该怎么写呢,多谢哈~! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 strsll = "insert into info(life) values('" + this.checkBox1.Checked.ToString() + "')"; bit 的值要给 0 或者 1 代表 假 / 真 strsll = "insert into info(life) values(" + this.checkBox1.Checked+ ")"; 这样试试,看你的数据库是什么类型 了,sqlserver2000只能插0,1如果是2005就可以直接用true ,false你最好还是用command.parameters来写sqlcommand cmd=new sqlcommand();cmd.text="insert into info (life) values (@life)";cmd.parameters.add(new sqlparameter("@life",this.checkbox.checked));conn.open();cmd.executenonquery();.....最好加上事务管理... strsll = "insert into info(life) values('" + this.checkBox1.Checked+ "')"; 你的语句写错了,如果是布尔类型你要转啊,你values('')怎么还有单引号呢?单引号就成了字符型 if (this.checkBox1.Checked){strsll = "insert into info(life) values(1)"; }else{strsll = "insert into info(life) values(0)"; } strsll = "insert into info(life) values('" + int(this.checkBox1.Checked)+ "')"; strsll = "insert into info(life) values('" + int(this.checkBox1.Checked).tostring()+ "')"; strsll = "insert into info(life) values('" + Convert.ToInt32(i(this.checkBox1.Checked)).tostring()+ "')"; 0/1就可以了true 0false 1 strsll = "insert into info(life) values(" + this.checkBox1.Checked+ ")"; 这样试试,看你的数据库是什么类型 了,sqlserver2000只能插0,1 如果是2005就可以直接用true ,false 你最好还是用command.parameters来写 sqlcommand cmd=new sqlcommand(); cmd.text="insert into info (life) values (@life)"; cmd.parameters.add(new sqlparameter("@life",this.checkbox.checked)); conn.open(); cmd.executenonquery();..... 最好加上事务管理... if(this.checkBox1.Checked == true){ string strsll = "insert into info(life) values('1')"; }else{ string strsll = "insert into info(life) values('0')"; }如checkbox1为真的话,表中插入1,否则为0! 用 三目效率高些 retValue = checkBox1.Checked?1:0; 然后strsll = "insert into info(life) values(" + retValue.ToString()+ ")"; 求解 上传文件怎么做到进度条,和流的理解 C#把数字三位分节方法 AutoCompleteExtender如何实现选择项不能选择 如何实现累似google文本框一输入字符,自动显示关联信息 查看端口是否在使用 write和writeline有什么区别啊 ? DataGridViewComboBoxColumn的录入方式问题 怎样实现撤消,重复这个功能?? 服务器上老是自动关闭iis 请教,C#中 netstream的结束符是什么?比如 java中是-1 初学asp.net?? C# 使用Dictionary<TKey,TValue> 遇到的问题?
这样试试,看你的数据库是什么类型 了,sqlserver2000只能插0,1
如果是2005就可以直接用true ,false
你最好还是用command.parameters来写
sqlcommand cmd=new sqlcommand();
cmd.text="insert into info (life) values (@life)";
cmd.parameters.add(new sqlparameter("@life",this.checkbox.checked));
conn.open();
cmd.executenonquery();.....
最好加上事务管理...
你的语句写错了,如果是布尔类型你要转啊,你values('')怎么还有单引号呢?单引号就成了字符型
{
strsll = "insert into info(life) values(1)";
}
else
{
strsll = "insert into info(life) values(0)";
}
true 0
false 1
这样试试,看你的数据库是什么类型 了,sqlserver2000只能插0,1
如果是2005就可以直接用true ,false
你最好还是用command.parameters来写
sqlcommand cmd=new sqlcommand();
cmd.text="insert into info (life) values (@life)";
cmd.parameters.add(new sqlparameter("@life",this.checkbox.checked));
conn.open();
cmd.executenonquery();.....
最好加上事务管理...
if(this.checkBox1.Checked == true)
{
string strsll = "insert into info(life) values('1')";
}
else
{
string strsll = "insert into info(life) values('0')";
}如checkbox1为真的话,表中插入1,否则为0!
然后strsll = "insert into info(life) values(" + retValue.ToString()+ ")";