Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace specific value in all cells when selecting from SQL table to dgv

I use a Select query to fill a DataTable from an SQL table and then use that DataTable as a DataSource for my DataGridView.

In my SQL table I have a column named 'status' that contains values between 1-3. When I display my dgv on my form I want every cell on column 'status' with value of 1 to change to "open".

How can I do that?

like image 747
Roi Snir Avatar asked Feb 24 '26 20:02

Roi Snir


2 Answers

Try something like this in your Select Query,

SELECT (CASE [status] WHEN 1 THEN 'Open' END) AS [status]
FROM table1
like image 132
Abdul Rasheed Avatar answered Feb 26 '26 08:02

Abdul Rasheed


You can use CASE statement:

SELECT CASE WHEN [status] = 1 THEN 'Open' 
            WHEN [status] = 2 THEN 'Something else' 
            ELSE 'One more time' END AS [status]
FROM table1
like image 43
gofr1 Avatar answered Feb 26 '26 10:02

gofr1