-3

I have a simple database over a hotel, this is for a cleaning service so I have a column named "status", this column has type int and are defined as 0 when a new room is added to database.

Problem is I would like the output of this column's value to be "Not cleaned" instead of "0". And "Cleaned" if the value is "1".

Any idea of how I can do this in the easiest way possible? I'm using Visual Studio 2015.

Thanks!

3
  • Easiest way? Change the boolean to a varchar in the database.... Commented Mar 13, 2017 at 18:41
  • Is that an int or a bit? How are you displaying? Did you want to change the database or just display a value? What is your code? I answered the question, but my answer makes way more assumptions than I would like because of your bad question. Commented Mar 13, 2017 at 18:42
  • Well, as I said in my question: It's an int and, as I also mention in my (bad) question, I want the value to be displayed as a text instead of an int. I want the value to be change in database from 0 to 1 IF the user change the "status", but I don't want the database to store the value as a varchar. I don't have any code yet, that's why I asked this question. I often code in PHP and I would like a solution like "if (status == 0) { echo "Not cleaned"; } else if (status == 1) {echo "Cleaned"; }". Commented Mar 15, 2017 at 19:21

4 Answers 4

1

Assuming the database is storing these as a bit not an int you can do the following:

string Cleaned = row["status"]?"Cleaned":"Not Cleaned"

Then use the string as you wish.

If you want to actually change the DB, that takes more work, you'd have to create a new column (or change the existing one, even harder) for the string value as a VARCHAR(15) (only really need 11 but I pad to be safe) then update that based on the bit in your old column.

UPDATE {Table} SET {NewColumn}=IIF(status=1,'Cleaned','Not Cleaned')
Sign up to request clarification or add additional context in comments.

Comments

1

Easiest Way, not the most correct design but the easiest

public enum RoomStatus : int
{
    NotCleaned = 0,
    Cleaned = 1
}

static void Main(string[] args)
{
    var e1 = (RoomStatus)0;
    var e2 = (RoomStatus)1;
}

1 Comment

Thank you. I will try this!
0

I assume you are using entity framework and you are referencing storing an enum.

If this is correct, check this link: How to save enum in database as string

Comments

0

You need to use OLEDB connection after this you have to use SQL UPDATE command. This will look like this :

UPDATE your table name SET status='Cleaned' WHERE status=1;

1 Comment

And what happens when you get an error due to the type mismatch? It's more likely status is an int or bit than a varchar, and even then it may not fit the 11 characters, if they wrote it to store the number.

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.