I'm using a datagridview in C# WinForms, with data from a Sybase database, and characters are not showing correctly. This is what I see:
Do you know how can I fix this?
I'm using a datagridview in C# WinForms, with data from a Sybase database, and characters are not showing correctly. This is what I see:
Do you know how can I fix this?
That's not how it works, CultureInfo serves a different purpose. You need the Encoding class. You'll get one with:
var enc = Encoding.GetEncoding(850);
Which you can then use to convert text, use enc.GetString().
Take a step back though, this encoding is really old, 25 years is a long time in software engineering. You really ought to consider upgrading this dbase. What's more, the encoding should be handled by your Sybase database provider. It should already convert text columns to Unicode. You should only need to convert yourself if the text is somehow contained in a blob.
Do you connect using a connection string? Try adding to your connection string:
;Current Language=Spanish
I frequently had this issue getting data from my sybase database into windows. You're storing the data as cp850 (which is fine), sybase can return it to you in whatever character set you wish, however it is up to the client to tell the server what character set it needs and the server will convert it for you before returning the data.
However by default the ado.net, oledb or odbc connections do not specify a client character set. Sybase won't apply any conversions, and windows (or your app) assumes that the data is in it's prefered character set.
The fix is to specify a character set when connecting. The one that worked for me is "iso_1". (You may also find WIN1252 as an alternative, but I've not tested that one)
So if you're using odbc or oledb then open up the connection manager, go to the second or third page and put "iso_1" in the character set box. You can also specify it in a connection string, but I can't remember the exact syntax possibly ";charset=iso_1".
If you're using ado.net, I'm sure you can do the same, but again I'm not certain of the exact syntax.