Error casting CHAR(1) SQL column as “char” in code

前端 未结 3 1504
小蘑菇
小蘑菇 2021-01-26 16:31

I\'m selecting from a SQL Server 2000 box CHAR(1) column called Combo_Label - it will always have a single A..Z character in

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-26 16:39

    The database and the Db access APIs have no concept of char. Your CHAR(1) is mapped to string.

    probably the most sensible option:

      string comboLabel = (string)formCombo.Rows[j]["Combo_Label"];
    

    but if you really want a char :

      char comboLabel = ((string)formCombo.Rows[j]["Combo_Label"])[0];
    

提交回复
热议问题