user70192
user70192

Reputation: 14204

C# - Decoding Data From an AS/400 iSeries

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!

Upvotes: 0

Views: 2255

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1499790

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.

Upvotes: 7

Related Questions