views:

18

answers:

1

In VS 2005 C#, While inserting Euro (€) Symbol into Db2 table, It is storing values correctectly. DISABLEUNICODE=1 parameter helped to store this correctly.

But when we try to read from the table, it is giving junk char as below.

"Spec GS 1"

Same code is working in VB 6.0 ADO

Could you please help me.


Code:

OdbcConnection con = new OdbcConnection();
OdbcDataAdapter dataAdapter = new OdbcDataAdapter("SELECT * FROM XXXX.XXXX" , con);
OdbcCommand odbcCommand =
    new OdbcCommand(
        "INSERT INTO   XXXX.XXXX( BREACH_TYPE,JURISDICTION,ACTIVE ,VERIFIED , UPDATED_TS , UPDATED_BY ,VERIFIED_TS ,VERIFIED_BY)VALUES ('Spec GS € 1','IRE','Y','Y',CURRENT TIMESTAMP,'XECCRT3',CURRENT TIMESTAMP,'XECCRT8')");

con.ConnectionString = "DSN=DSNT;UID=xxxxxx;PWD=xxxxxx;MODE=SHARE;DBALIAS=DSNT;DISABLEUNICODE=1;PATCH1=1024;LONGDATACOMPAT=1;LOBMAXCOLUMNSIZE=1048575;PATCH2=6;";
con.Open();

odbcCommand.Connection = con; 
odbcCommand.ExecuteNonQuery();

dataAdapter.SelectCommand.CommandTimeout = 0;

DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet);
DataTable result = dataSet.Tables[0];

string Text = result.Rows[0][0].ToString();

MessageBox.Show(Text = result.Rows[0][0].ToString());

con.Close(); 
A: 

After reading the text from DataSet, used the followign encoding function to display correct data.

 private static string ConvertToAsciiString(string str)
{            
    Encoding source = Encoding.Default ;
    Encoding dest = Encoding.Unicode ;

    // Convert the string into a byte[].
    byte[] sourceBytes = dest.GetBytes(str);

    // Perform the conversion from one encoding to the other.
    byte[] destBytes = Encoding.Convert(source, dest, sourceBytes);

    string asciiString = dest.GetString(destBytes);
    asciiString = asciiString.Replace("\0", string.Empty);


    return asciiString; 
}
Gunasekaran