tags:

views:

92

answers:

3

I have a boolean field in a MySQL database. When displaying the selected rows from the DB on the datagrid in C#, I want this field to be displayed as "true" or "false".

Can somebody help me out in telling how can I do it?

+7  A: 

Typically, this will happen automatically. It depends on how you're pulling the Boolean across into C#, but it will normally get treated as a bool, which in turn will turn into "True" or "False" when it's ToString() method is called.

Reed Copsey
More specifically, "True" or "False" (note the capitalization)
Mark
@Mark: Corrected.
Reed Copsey
+4  A: 
String.Format("The boolean value is {0}", boolValue ? "true" : "false");

You could wrap the ternary statement in some ToFriendlyString() extension method. This will allow you to say ANYTHING; true/false, yes/no, up/down, black/white, whatever the Boolean value really represents in your model.

Boolean.ToString() returns a capitalized "True" or "False"; you can format that as necessary using ToLower().

KeithS
A: 

The above answers will work for you in C#, however if you can do it at the Database level:

CASE WHEN FIELD_NAME 1 THEN 'TRUE' ELSE 'FALSE' END AS [FIELD NAME]

This would require you to change the return type to a string/varchar.

Jack Marchetti