问题描述
我有一个CSV由一个过程,我不控制任何输出头文件
I have a CSV file with no header output by a process I do not control:
FOO,<auto>,12345678,8005882300, ,2
FOO,<auto>,23456789,2128675309, ,2
FOO,<auto>,34567890,3125577203, ,2
FOO,<auto>,45678901,9198423089, ,2
我试图用传统的ASP与ADO然后使用这个code打印出的电话号码进行访问:
I'm trying to access it using Classic ASP with ADO then print out the phone number using this code:
stmt = "SELECT * FROM baz.txt"
connectstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=I:;Extended Properties='Text;HDR=No;FMT=Delimited'"
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open connectstring
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open stmt, conn, adLockOptimistic, , adCmdText
If Not rs.eof Then
Data=rs.GetRows()
End If
for r = 0 to UBound(Data,2)
response.write(Data(3,r) & "<br>")
next
虽然我有 HDR
标记设置为否
的结果从未包括第一行:
Even though I have the HDR
flag set to No
the result set never includes the first row:
2128675309
3125577203
9198423089
我在做什么错,它出现在第一行仍然被跳过?
What am I doing wrong that it appears the first row is still being skipped?
推荐答案
我想答案张贴到万一有人我自己的问题别人跑进在未来类似的情况。
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.
这篇关于为什么不是ADO扩展属性&QUOT; HDR =否];标志被在这里服从?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!