I have a sql query that returns rows of data and one field returns a 1 (which means yes) or a 0 (which means no). On my vb.net page, how do I replace the 1 with a Yes and the 0 with a No? Or do I do this in the sql? How do I do this in sql?
Never make important decisions on a Monday!
By default, VB.Net can understand 1 as Yes and 0 as No.
I believe you are using those DB values for your Boolean Operations.
Try to use If <DBValue> then <Operation>.
If you are really need Yes/No .... Declare boolean variable in VB.net and set those variables.
Thanks and Regards,
Venu B Pavuluri
SELECT column1, column2,
WHEN '1' THEN 'Y'
WHEN '0' THEN 'N'
Hope it helps.
If this post is useful to you, please mark it as answer.
You can do this either on your page or from SQL by using a CASE statement.
SELECT CASE WHEN col1=1 THEN 'YES' ELSE 'NO' END as col1 FROM yourTable
What datatype your using for the 1/0/Y/N ? i assume CHAR(1) ?
Why dont you use BIT ? which is 0 and 1 - True or False
I use BIT for all my checkboxes in asp.net and c#
dr2 = datareader
thw_Enabled = SQL Column with BIT as datatype
cbEnabled = Checkbox in asp.net c# front end
cbEnabled.Checked = Convert.ToBoolean(dr2["thw_Enabled"].ToString());
if you need to do it in the VB code, you can use String.Format like this:
Assuming that myValue is a numeric, it will display "yes" for any non-zero value, and "no" for any zero values. Replace yes and no in that format string as you need.