且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么不是ADO扩展属性" HDR =否];标志被在这里服从?

更新时间:2022-06-02 08:02:04

我想答案张贴到万一有人我自己的问题别人跑进在未来类似的情况。

I wanted to post the answer to my own question in case someone else runs into a similar situation in the future.

有关我我的简单化code,并在这样做我已经删掉了使得它打破了东西后的目的。在code实际上是包含在一个循环内遍历多个文件在​​多个子文件夹:

For the purposes of the post I had oversimplified my code, and in so doing I had removed the thing that was making it break. The code was actually contained within a loop to iterate through several files in several subfolders:

path = "I:"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set dirFolders = objFSO.GetFolder(path).SubFolders

For Each subFolder in dirFolders
  Set dirFiles = objFSO.GetFolder(subFolder).Files
  For Each bar in dirFiles
    stmt = "SELECT * FROM " & bar
    connectstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& path &";Extended Properties='Text;HDR=No;FMT=Delimited'"
    [...]

在实践中,这是实际上获得通过,以ADO:

In practice, this is what was actually getting passed to ADO:

stmt = "SELECT * FROM I:\20140509\baz.txt"
connectstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=I:;Extended Properties='text;HDR=No;FMT=CSVDelimited'"

具有包含在语句 CONNECTSTRING 的完整路径,并在一个不完整的路径造成的 HDR 不容忽视的标志。这本来是很好,如果ADO已经打破少一点微妙的,当我喂了它,但它是它是什么。

Having the full path included in stmt and an incomplete path in connectstring caused the HDR flag to be ignored. It would have been nice if ADO had broken a little less subtly when I fed that to it, but it is what it is.

修正code:

For Each path in dirFolders
  Set dirFiles = objFSO.GetFolder(path).Files
  For Each bar in dirFiles
     stmt = "SELECT * FROM " & objFSO.GetFileName(bar)
     connectstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& path &";Extended Properties='Text;HDR=No;FMT=Delimited'"

归根结底,这是一个提醒,在百思不得其解code夹紧一对夫妇的Response.Write 语句是一个好主意,当它不工作,你喜欢预计,剥离下来到单刀直入,以确保您正在寻找在正确的地方。

Ultimately, it's a reminder that chucking a couple of response.write statements at puzzling code is a Good Idea, and when it doesn't work like you expect, to strip it down to brass tacks to make sure you're looking in the right place.