jina
jina

Reputation: 125

How to assign true or false value to column

How to assign a true or false value to a column. I am getting the count of values for an ID. Then checking the count and assigning true or false boolean values to it. In the view side, I need to check if the value coming is true or false, and based on the true or false value I need to display different text in my view. But now my Item.Complete value is coming as false always. what I am doing wrong here?

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;
    }

}
  }
}

Upvotes: 0

Views: 407

Answers (1)

Ahmad Raza
Ahmad Raza

Reputation: 848

Instead of Passing yes andNo Try using 1 and 0

Upvotes: 2

Related Questions