Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting c# char variable data to ADO Char(1) field [duplicate]

Tags:

c#

I am experiencing this rather weird decimal addition to my char value during the conversion. enter image description here

Tried the following conversion but the decimal value just keeps on getting assigned along with the char to the variable:

  1. Convert.ToChar(Console.ReadLine());
  2. Console.ReadLine().ToString()[0];
  3. Console.ReadKey().KeyChar;

Object containing char field: objekt

Schema:

Daten

Error @ DAL : System.Data.SqlClient.SqlException: 'String or binary data would be truncated.

USING : .NET Standard Libs

like image 381
MantiCore Avatar asked Jan 31 '26 12:01

MantiCore


1 Answers

Your char is just displayed with the decimal value before it. So the decimal value is the ASCII value of the character. You could easily test this by printing the value and you'd see that it only contains the character. If you want to test it while debugging, I'd suggest using employeeGrade.ToString() in the watch windows.

It wouldn't even be possible for a char to hold the value 90'Z' because it would be multiple characters. You can see the ASCII values in a ASCII table like this: http://ascii.cl/.

like image 61
MetaColon Avatar answered Feb 02 '26 01:02

MetaColon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!