Error while executing CHAR (1) SQL column as "char" in code
I choose from a column CHAR(1)
of SQL Server 2000 with the name of the column Combo_Label
- it will always contain one character A
.. Z
. During testing, it converts the first 70 or so items without issue, but then runs into Invalid Cast Exception
.
This is problem:
char comboLabel = (char)formCombo.Rows[j]["Combo_Label"];
This is a screenshot of the watch list showing some ways to evaluate it.
Any thoughts on why this is happening?
source to share
There is no concept in database and Db access API char
. Yours is CHAR(1)
displayed on string
.
probably the smartest option:
string comboLabel = (string)formCombo.Rows[j]["Combo_Label"];
but if you really want char
:
char comboLabel = ((string)formCombo.Rows[j]["Combo_Label"])[0];
source to share