Hello,
I am using the standard .NET OdbcConnection to connect to an AS/400 iSeries database. I am able to query this database. Unfortunately, there are some fields that appear to be encoded. How do I decode these values in C#? I have tried the following:
string text = string.Empty;
if (bytes.Length > 0)
{
    ASCIIEncoding encoder = new ASCIIEncoding();
    text = encoder.GetString(bytes);
}
return text;
The bytes variable represents the data that needs to be decoded. Unfortunately, I am not having any luck. I have been told that the data will return correctly if I setup an ODBC data source on my Windows machine and check the "Convert binary data (CCSID65535) to text" checkbox in the translation tab. However, I want to use pure C#. Any ideas? Am I way off?
Thanks!
- 
                        Chances are it's using EBCDIC. You could try using Encoding.GetEncoding(37) or you could use the EBCDIC encoding I wrote a while ago. Kevin : Beat me to it, Jon. EBCDIC was my first thought too.: You're the man. This removed my headache big time. Thank you so much for your help!Richard : Would suggest using one of the names ("IBM037" or similar see http://msdn.com/System.Text.Encoding for a full list) as this avoids the magic number.Jon Skeet : @Richard: It changes a magic number into a magic string :) It would be nice if these were exposed via the Encoding API...Richard : @Jon: Like Encoding.GetEncodings "Returns an array containing all encodings"?
 
0 comments:
Post a Comment