0

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?

1
  • What technology? Winforms, WPF, ASP.NET? Commented Oct 27, 2010 at 20:42

3 Answers 3

7

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.

Sign up to request clarification or add additional context in comments.

1 Comment

More specifically, "True" or "False" (note the capitalization)
4
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().

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.