-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!

Rodin
  • 1
  • 1
  • Easiest way? Change the boolean to a varchar in the database.... – Tony Hopkinson Mar 13 '17 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. – Andrew Mar 13 '17 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"; }". – Rodin Mar 15 '17 at 19:21

4 Answers4

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')
Andrew
  • 1,544
  • 1
  • 18
  • 36
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;
}
Travis Acton
  • 4,292
  • 2
  • 18
  • 30
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

Community
  • 1
  • 1
Cory Knutson
  • 164
  • 8
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;
Tamas B.
  • 181
  • 1
  • 1
  • 7
  • 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. – Andrew Mar 13 '17 at 18:51