使用 ODBC ADO.NET 从 Db2 代码页 1252 读取数据 - 欧元 (€) 符号未正确检索
在 VS 2005 C# 中,将欧元 (€) 符号插入 Db2 表时,它正确存储值。 DISABLEUNICODE=1 参数有助于正确存储它。
但是当我们尝试从表中读取时,它给出了如下垃圾字符。
“Spec GS 1”
相同的代码在 VB 6.0 ADO 中工作,
您能帮助我吗?
代码:
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();
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();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从DataSet读取文本后,使用以下编码函数显示正确的数据。
After reading the text from DataSet, used the following encoding function to display correct data.