如何为列分配真值或假值。我正在获取ID的值计数。然后检查计数并为其分配真或假布尔值。在视图方面,我需要检查传入的值是true还是false,并且基于true或false值,我需要在视图中显示不同的文本。但是现在,我的Item.Complete值总是变为false。我在这里做错了什么?
var sqlst = @"select count(*) as columnCount, mem_name as Name, mem_add as address from my_table whereid = 1234"
using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MY_CONNECTION"].ConnectionString))
{
connection.Open();
using (var sqlCommand = new SqlCommand(sqlst, connection)
using (var sqlResult = sqlCommand.ExecuteReader())
{
while (sqlResult.Read())
{
var checkcount = Convert.ToInt32(sqlResult["columnCount"].ToString());
if (checkcount != 0)
{
Item.Complete = sqlResult["columnCount"].ToString() == "YES" ? true:false;
}
else
{
Item.Complete = sqlResult["columnCount"].ToString() == "NO" ? true: false;
}
}
}
}
答案 0 :(得分:3)
而不是传递yes
和No
,请尝试使用1和0