我如何关联“真"消息?而“假"组合框中的值在数据库中为0还是1? [英] How Do I Associate "True" And "False" Values On Combobox To 0 Or 1 In Database?

查看:90
本文介绍了我如何关联“真"消息?而“假"组合框中的值在数据库中为0还是1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,当我的组合框中的值为"true"和"false"时,如何设置tinyint(0或1)类型的数据库值?


例如,如果我在组合框上选择"true",则会将数据库值设置为1,如果我选择"false",则会根据带有sql查询的按钮将值设置为0.


你能帮忙的话,我会很高兴! ;)

I have a question, how can i set a database value of type tinyint(0 or 1) when the values in my combobox are "true" and "false"?


For example, if i choose the "true" on combobox it sets a database value of 1 and if i choose "false" it sets the value to 0 according to a button with the sql query.


Any help would be nice! ;)

推荐答案

string comboValue = "true";
bool v = bool.Parse(comboValue); // use TryParse instead
int yourDbValue = v ? 1 : 0;



如果您经常这样做,则可以对字符串进行扩展方法以将true \ false \"1" \"0"转换为1或0.



If you do this a lot you can make an extension method on string to convert true\false\"1"\"0" to 1 or 0.


这篇关于我如何关联“真"消息?而“假"组合框中的值在数据库中为0还是1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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