求c#生僻字的处理,在线等 报什么错误 发出来看下 是不是xxx不是xx编码中的问题? 你原来录入数据库的文件编码是什么 utf8? gbk? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 getlistinfo[i] = GetEncodingString(oledr[i].ToString());public static string GetEncodingString(string srcString) { Encoding e8859Encode = Encoding.GetEncoding("iso-8859-1"); Encoding srcEncode = Encoding.GetEncoding("gb2312"); Encoding dstEncode = Encoding.Unicode; byte[] srcBytes = e8859Encode.GetBytes(srcString);//用iso-8859-1去转换源字符串 byte[] dstBytes = Encoding.Convert(srcEncode, dstEncode, srcBytes);//但是,是从gb2312转到unicode的 char[] dstChars = new char[dstEncode.GetCharCount(dstBytes, 0, dstBytes.Length)]; dstEncode.GetChars(dstBytes, 0, dstBytes.Length, dstChars, 0); return new string(dstChars); } system.invalidcastexception:由于符号不匹配或数据溢出以外的其他原因,未能转换数据值 我现在报错的不是在字符编码转换的时候,是执行.tostring()的时候 用Convit.ToString(datareader[i])试试; informix中该字段类型是varchar(32,8) byte[] srcBytes = e8859Encode.GetBytes(srcString);//用iso-8859-1去转换源字符串这是不对的已经是string了,就肯定已经是utf-8编码了,在编码转换过程中,始终要用 byte[] ,传进来的和传出去的都得是 byte[] 。 问题是oledr[i].ToString()这一步就已经出错了 OleDbConnection objConnection = new OleDbConnection(strConnection);OleDbCommand olesql = new OleDbCommand();try { objConnection.Open(); olesql.CommandText = sqlcmd.ToString(); olesql.Connection = objConnection; OleDbDataReader oledr = olesql.ExecuteReader();while (oledr.Read()) {getlistinfo[i] = GetEncodingString(oledr[i].ToString());}}catch (Exception ex) { MessageBox.Show("获取打印数据失败" + ex.ToString()); }我监视了oledr[i],就报错取不到了 大家开发Winform项目把数据库连接字符串写在app.config文件里吗? 关于datatable 读取excel的问题 关于建立多个线程 C# winform listView如何绘制线条? 长度怎么读取? 想做一个只能输入数字的文本框,是用 用户控件做 还是怎么?给个最常用方法 谢谢 c#中OracleDataReader的item属性如何使用呀!!! 为什么我的CSS样式表没用了? 请问各位高手,无法加载程序集是什么意思 怎么把DataTable里的所有Row的RowState设置为Added? C#在win7下為何只有調試模式才能讀寫 不知道web控件的id和name怎么操作他们
{
Encoding e8859Encode = Encoding.GetEncoding("iso-8859-1");
Encoding srcEncode = Encoding.GetEncoding("gb2312");
Encoding dstEncode = Encoding.Unicode;
byte[] srcBytes = e8859Encode.GetBytes(srcString);//用iso-8859-1去转换源字符串
byte[] dstBytes = Encoding.Convert(srcEncode, dstEncode, srcBytes);//但是,是从gb2312转到unicode的
char[] dstChars = new char[dstEncode.GetCharCount(dstBytes, 0, dstBytes.Length)];
dstEncode.GetChars(dstBytes, 0, dstBytes.Length, dstChars, 0);
return new string(dstChars); }
这是不对的
已经是string了,就肯定已经是utf-8编码了,在编码转换过程中,始终要用 byte[] ,传进来的和传出去的都得是 byte[] 。
OleDbCommand olesql = new OleDbCommand();
try
{
objConnection.Open();
olesql.CommandText = sqlcmd.ToString();
olesql.Connection = objConnection;
OleDbDataReader oledr = olesql.ExecuteReader();
while (oledr.Read())
{
getlistinfo[i] = GetEncodingString(oledr[i].ToString());
}
}
catch (Exception ex)
{
MessageBox.Show("获取打印数据失败" + ex.ToString());
}
我监视了oledr[i],就报错取不到了