Hi
I am getting error - operator == cannot be applied to operands of type object and boolean.
Status is of type bit .
String Status = row["status"] == true ? "Active" : "Blocked";
Thanks
Hi
I am getting error - operator == cannot be applied to operands of type object and boolean.
Status is of type bit .
String Status = row["status"] == true ? "Active" : "Blocked";
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sam HobbsPosted Aug 16, 2024, 6:03 PM
I assume that
rowis aSqlDataReader. I think it is saying thatrow["status"]is an object, as in:SqlDataReader.Item[] Property (System.Data.SqlClient) | Microsoft Learn
https://learn.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqldatareader.item?view=netframework-4.8.1
If so then it must be converted to a boolean. And then you do not need the
== truepart.The following article is an article about
SqlDataReader.Working With SqlDataReader Class in ADO.NET
https://www.c-sharpcorner.com/UploadFile/718fc8/working-with-sqldatareader-class-in-ado-net
It shows use of that class for a
stringfield. Ifstatusis abooleanthen you need to cast to aboolean.