简体   繁体   English

C#OLEDB驱动程序未读取空字符

[英]C# OLEDB driver not reading null character

I am trying to read a dbf file through ADO using the FoxPro OLEDB driver. 我正在尝试使用FoxPro OLEDB驱动程序通过ADO读取dbf文件。 I can query fine however there are some special characters which do not seem to be coming through. 我可以很好地查询,但是有些似乎无法通过特殊字符。 They are not printable characters as disappear when clicked on however are definitely not the same via OLEDB as they are in FoxPro. 它们不是可打印的字符,因为单击时会消失,但是通过OLEDB肯定与FoxPro中的字符不同。

For example, the following field through Visual FoxPro: 例如,通过Visual FoxPro的以下字段:

在此处输入图片说明

When this is accessed through OLEDB it displays as the following: 通过OLEDB访问时,显示如下:

在此处输入图片说明

I've narrowed this down to the fact that the first string contains the ASCII code 0 (null) character as the 10th character - this is valid however so I do not wish to remove it, but whatever I try the string ends after 9 characters when reading with ADO. 我将其缩小为第一个字符串包含ASCII代码0(空)字符作为第十个字符的事实-这是有效的,但是我不希望删除它,但是无论我尝试什么,字符串都以9个字符结尾用ADO阅读时。

You don't show us any code and the image links are broken, we are left out with guesses. 您没有向我们显示任何代码,并且图像链接已损坏,我们被排除在猜测之外。 I have been using VFPOLEDB driver from C# for years and do no have this problem. 我多年来一直在使用C#的VFPOLEDB驱动程序,并且没有这个问题。 I believe you are trying to describe a problem that exists on C# side and not VFP side. 我相信您正在尝试描述C#端而非VFP端存在的问题。 In VFP even the char(0) is a valid character. 在VFP中,即使char(0)也是有效字符。 In C# however (docs are misleading IMO, says this is not the case but it is) strings are ASCIIZ strings where char(0) is accepted as the end of string. 但是在C#中(文档误导了IMO,但事实并非如此),字符串是ASCIIZ字符串,其中char(0)被接受为字符串的结尾。 This should be your problem. 这应该是你的问题。 You could simply read as a byte array instead, casting the field to a blob. 您可以简单地读取为字节数组,而是将字段强制转换为Blob。 Something like: 就像是:

Instead of plain SQL like this: 而不是像这样的普通SQL:

select myField from myTable

Do like this and cast: 这样做并投射:

select cast(myField as w) as myField from myTable

EDIT: Images were not broken but blocked for me by my ISP, go figure why. 编辑:图像没有损坏,但被我的ISP阻止了,请查明原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM