// Convert the string into a byte[].
byte[] srcBytes = srcEnoding.GetBytes(srcString);
// Perform the conversion from one encoding to the other.
byte[] desBytes = Encoding.Convert(srcEnoding, desEncoding, srcBytes);
// Convert the new byte[] into a char[] and then into a string.
// This is a slightly different approach to converting to illustrate
// the use of GetCharCount/GetChars.
char[] desChars = new char[desEncoding.GetCharCount(desBytes, 0, desBytes.Length)];
desEncoding.GetChars(desBytes, 0, desBytes.Length, desChars, 0);
string desString = new string(desChars);
// Display the strings created before and after the conversion.
return desString;
现在是这样:
1.除了iso_1,连接串中charset设置成其他的都报错
2.连接串设置charset=iso_1或是没有设置charset,连接成功,但运行中文sql都出错,提示:
"
{"ERROR [01004] [MERANT][ODBC Sybase ASE driver]String data translation caused data truncation.\r\nERROR [HY000] [MERANT][ODBC Sybase ASE driver][SQL Server]Unclosed quote before the character string '一些中文字符'.\n\r\nERROR [42000] [MERANT][ODBC Sybase ASE driver][SQL Server]Incorrect syntax near " '一些中文字符'.\n" }
"
还是出错,ERROR [01000] [MERANT][ODBC Sybase ASE driver][Sybase ASE]Cannot find the requested character set in Syscharsets: name = 'GB_2312'. ERROR [01000] [MERANT][ODBC Sybase ASE driver][Sybase ASE]No conversions will be done
我的连接串:
driver=SYBASE ASE ODBC Driver;NA=server,5000;uid=sa;pwd=;Database=dbName;charset=GB_2312,是不是数据库安装的时候少了这个字符集?可我在sybase自带的sql advantage控制台运行中文sql没有问题啊
感谢Yuna_2z(其实游戏是一艺术,而我只是身陷其中!) ( ) 帮顶和愚翁老爷的作答
在下在connectionstring中设置charset = iso_1时可正常连接数据库,设置charset = gb2312时连接出错,提示“Cannot find the requested character set in Syscharsets: name = 'gb2312'. ERROR [01000] [MERANT][ODBC Sybase ASE driver][Sybase ASE]No conversions will be done”系统无此字符集?请问如何解决?再找找看小刀的解决方法。