Hi
I am getting error - operator == cannot be applied to operands of type object and boolean.
Status is of type bit .
C#
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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sam HobbsRank #107 · 20.5K reputationPosted Aug 16, 2024, 2:03 PM EDT
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.