[英]Using C#, is it possible to make System.Data.OleDb handle special characters?
I have an existing C# project that reads a text file and loads it into an Oracle DB using System.Data.OleDb as provider. 我有一个现有的C#项目,它读取文本文件并使用System.Data.OleDb作为提供程序将其加载到Oracle DB中。 Problem is that if the file has upper ascii characters (eg ÀÑÓ, non-breaking space) it always generates an error when it tries to load it into Oracle:
问题是,如果文件具有上部ascii字符(例如ÀÑÓ,非中断空格),它在尝试将其加载到Oracle时总是会生成错误:
Error is: OLEDBConnection Command Parameter data value could not be converted for reasons other than sign mismatch or data overflow . 错误是: OLEDBConnection命令由于符号不匹配或数据溢出以外的原因,无法转换参数数据值 。
Our Oracle can accept upper ascii characters (insert via SQL*PLUS works fine), it is System.Data.OleDb that is having issue. 我们的Oracle可以接受上面的ascii字符(通过SQL * PLUS插入工作正常),它是有问题的System.Data.OleDb。
Anyone know if there is a setting to change this? 有人知道是否有改变这个的设置? Can't believe that that only accepts AZ-0-9.
不敢相信那只接受AZ-0-9。 Looked thru a ll documentation but couldn't find anything.
通过ll文档查看,但找不到任何东西。
If it can't, how do you let OLEDB know to escape the character. 如果它不能,你怎么让OLEDB知道逃脱角色。 Tired putting \\ in the file before special characters, but it still errors with same message.
在特殊字符之前将文件放在文件中,但它仍然存在相同消息的错误。
Usually this is possible without any problem... since you don't provide much detail only some general pointers: 通常这是可能的,没有任何问题...因为你没有提供太多细节只有一些一般的指针:
SELECT parameter, value FROM nls_database_parameters WHERE parameter = 'NLS_CHARACTERSET';
SELECT parameter, value FROM nls_database_parameters WHERE parameter = 'NLS_CHARACTERSET';
来检查这一点SELECT parameter, value FROM nls_database_parameters WHERE parameter = 'NLS_CHARACTERSET';
OLEDB.NET=True
OLEDB.NET=True
Other points to check could be OS and Client and OLEDB versions... some have bugs or strange behaviour... 其他要检查的点可能是操作系统和客户端以及OLEDB版本......有些还有错误或奇怪的行为......
You may have to use HEX conversions. 您可能必须使用HEX转换。 For example %c4 is Ä.
例如,%c4是Ä。
Try that and let me know if that works. 试试看,如果有效,请告诉我。 Here are the conversion functions you can use.
以下是您可以使用的转换功能。
internal String convertAsciiTextToHex(String asciiText)
{
StringBuilder sBuffer = new StringBuilder();
for (int i = 0; i < asciiText.Length; i++)
{
sBuffer.Append(Convert.ToInt32(asciiText[i]).ToString("x"));
}
return sBuffer.ToString().ToUpper();
}
internal String convertHexToAsciiText(String hexString)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hexString.Length; i += 2)
{
string hs = hexString.Substring(i, 2);
sb.Append(Convert.ToChar(Convert.ToUInt32(hs, 16)));
}
String ascii = sb.ToString();
return ascii;
}
您的数据类型和参数类型是nvarchar2吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.