[英]How do I convert a boolean value to an int and save it to a MySQL table in C#?
I'm trying to convert a bool to an int and then save that into a MySQL table, but I get the wrong values: 我正在尝试将bool转换为int,然后将其保存到MySQL表中,但是得到了错误的值:
Example: 例:
Enabled = false;
Console.WriteLine(Enabled ? 1 : 0); //returns 0
DatabaseClient.AddParamWithValue("user_id", Session.GetUser().Id);
DatabaseClient.ExecuteQuery("UPDATE users SET friend_chat = " + (Enabled ? 1 : 0) + " WHERE Id = @user_id LIMIT 1;"); // returns empty
Enabled = true;
Console.WriteLine(Enabled ? 1 : 0); //returns 1
DatabaseClient.AddParamWithValue("user_id", Session.GetUser().Id);
DatabaseClient.ExecuteQuery("UPDATE users SET friend_chat = " + (Enabled ? 1 : 0) + " WHERE Id = @user_id LIMIT 1;"); // returns 0
I think you simply have the 2 mixed up. 我认为您只是将两者混在一起了。 When Enabled is true, the first option will be chosen;
当Enabled为true时,将选择第一个选项;否则为false。 ie 1
即1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.