ADO 和 Microsoft 文本驱动程序 - 字段分隔符问题
我使用 VB6 和 ADO 以及 Microsoft Text Driver 从 ASCII 文件导入数据。该文件以逗号分隔,但在文本数据字段周围还包含双引号。这些字段也是固定宽度的。
我遇到的问题是,只要其中一行内容中包含引号 双引号,驱动程序就会错误地读取列。这发生在“零件描述”列内,即左起第二列。发生这种情况时,右侧的列都是空值,而文本文件中的情况并非如此。
我认为最好只使用逗号作为分隔符。但是,我相信逗号也出现在“部分描述”列中,因此这意味着我应该将文件加载为固定宽度。我不知道有什么方法可以做到这一点,除非我可以在 schema.ini 文件中指定这一点。
关于如何解决这个问题有什么想法吗?
编辑:
您可以在 Schema.ini 文件中指定固定宽度。然而,在我看来,也作为分隔符/限定符存在的逗号和引号将阻止其正常工作。看起来我可能必须“手动”读入文件并以我自己的格式写回,然后再使用 MS Text 驱动程序加载它。仍在寻找其他意见。
I'm using VB6 and ADO together with the Microsoft Text Driver to import data from an ASCII file. The file is comma delimited but it also contains double quotation marks around text data fields. The fields are also fixed width.
I'm having a problem that the driver reads the columns incorrectly any time one of the rows contains a quotation mark double quotation inside the content. This happens inside the "part description" column which is the second column from the left. When this occurs, columns to the right are all Null value, which is not the case in the text file.
I think it would be better to use only the commas as delimiters. However, I believe that commas also occur in the "part description" column so this means I should really load the file as fixed width. I'm not aware that there is any way of doing this unless I can specify this in the schema.ini file.
Any ideas on how to resolve this?
Edit:
You are allowed to specify fixed width in your Schema.ini file. However, it appears to me that the commas and quotation marks that also exist as delimiters/qualifiers will prevent this from working properly. It looks like I may have to "manually" read the file in and write it back out in my own format before I load it using the MS Text driver. Still looking for other opinions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会尝试更改注册表中 Jet 文本引擎(如果您正在使用的)
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Text 键处的
。我认为默认值为Format
值CSVDelimited
,但您可以将其更改为FixedLength
。请参阅 http://msdn.microsoft.com/en-us/library/ms974559。 aspx可能值得补充的是,尽管您有一个
Schema.ini
文件用于设置,但在某些选项上注册表无论如何都会推翻它们实际上,查看我提供的链接,您似乎必须使用
schema.ini
文件来存储固定长度的文件。您是否尝试过类似下面的指定宽度的方法?I would try changing the
Format
value in the registry for the Jet text engine (if that's what you're using) at the keyHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Text
. I think the default isCSVDelimited
but you would change this toFixedLength
. See http://msdn.microsoft.com/en-us/library/ms974559.aspxIt's probably worth adding that although you have a
Schema.ini
file for settings, on some options the registry overrules them anywayActually, looking at the link I supplied, it seems you have to use a
schema.ini
file for fixed-length files. Have you tried something like the following, which specifies the width?我对区域设置格外谨慎——一些用户更改了默认列表分隔符。通常使用
schema.ini
修复此问题,如下所示:I'm extra precautious with regional settings -- some users change default list separator. Usualy fix this with
schema.ini
like this: