如何打印true而不是1 [英] how to print true instead of 1

查看:182
本文介绍了如何打印true而不是1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个代码,当我单击复选框时,我必须在其中打印出正确的代码

i m writing a code in which i have to print true when checkbox is clicked now i''ve come up with this

bool bResume = chkbResume.Checked;
            MySqlConnection MyCon = new MySqlConnection("server=localhost; Database = nikz; user id=root; password=nikhil; pooling=false;");

            MyCon.Open();

            MySqlCommand command = new MySqlCommand();

 command.Parameters.Add("@resume", bResume);
          
            string SQL = "INSERT INTO LFT_employees (S_no,Emp_no,Name,DOB,Contact,Alternate_Number,DOJ,DOA,Email_id,DOL,Status,P_F_number,Pan_number,Resume) VALUES (@Sno,@EmpNo,@EmpName,@Dob,@Contact,@altno,@DOJ,@DOA,@Email_id,@DOL,@status,@PFno,@pan_no,@resume)";
            command.Connection = MyCon;
            command.CommandText = SQL;
            command.ExecuteNonQuery();
            MyCon.Close();



这会在名为resume的列中打印1,但我想打印true,该怎么办????



this prints 1 in column named resume but i want to print true ,how can that be done?????

推荐答案

好吧,mysql没有布尔值的文本.布尔字段改为使用0-1逻辑,但您不必为此担心.您可以根据需要使用char字段,但这是错误的方法.选择 IF [
Well, mysql has no text valued boolean. Bool fields use 0-1 logic instead, but you don''t need to worry about this. You can use char field if you want, but it is a wrong approach. When selesting IF[^] statement can convert int values to string, but this is also not needed. .NET will simply handle all non-zero values as true.


您是不是要插入布尔值作为字符串?说对/错?
如果是这样,那么您需要将列类型修改为可以接受字符串并执行的操作

Did you mean you want to insert bool value as string? say true/false?
if so then you need to modify your column type as something which accepts string and do

string bResume = chkbResume.Checked ? bool.TrueString : bool.FalseString;







or

string bResume = bResume.ToString().ToLower()



足够



will suffice


您只需要更改一行

you only need to change one line

command.Parameters.Add("@resume", bResume.ToString().ToLower());


这篇关于如何打印true而不是1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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