Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can handle it in 1 of 2 ways.</p> <p>1) Instead of returning the data as a bit, do the casting in your query to have it return Buy/Sell as a string based on the value. This will only really work well if your grid is read-only. If you need to be able to add/edit data, it would get messy to convert your Buy/Sell back to a bit and enforce that the user could only enter buy/sell. You'd probably want to use method 2 if you need to add/edit data.</p> <p>e.g. let's say your column name is called BuySell and is of type bit</p> <pre><code>SELECT CASE WHEN BuySell = CAST(0 AS BIT) THEN 'Buy' ELSE 'Sell' AS BuySell FROM TableName </code></pre> <p>2) You will have to turn off "Autogeneratecolumns" on the DataGridView and setup your columns manually. If your grid is read-only, I'd add a text column for your buy/sell column that maps to your bit value. Then in the Cell_Formatting event for the grid, update the value based on the bit. Something like the below:</p> <pre><code>private void dgv_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (dgv.Columns[e.ColumnIndex].Name == "buysell") { if (e.Value != null) { if (e.Value.ToString() == "1") { e.Value = "Sell"; } else { e.Value = "Buy"; } } else { e.Value = "Buy"; } } } </code></pre> <p>If your grid needs to be editable, setup a DataTable that represents your Buy/Sell values with a displaymember and valuemember. Bind that as the datasource for a combobox column. Now loading the data will correctly display Buy/Sell in the combobox and for new rows when you select a value from the drop-down it will populate your underlying datasource with the correct bit value.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload