讓我先說,我很感激有一個地方去,當我需要一些代碼幫助,我當我看到人們試圖助陣更是心存感激,所以在這裏給大家感謝你開始即使你沒有答案,也要看我的問題/問題。在記錄集中讀取CSV?
雖這麼說,在我的問題/問題:
我一直試圖讓這個工作,但我似乎無法找到語法錯誤! :-(
誰能幫我...
下面是代碼:
dim strPathtoCSVFolder,strPathtoCSVFile,strPathtoCSVFileTWO
strPathtoCSVFolder="D:\classic_asp\test\" & Request.QueryString("XTNO") & "\Data\"
strPathtoCSVFile="Unit_" & Request.QueryString("XTNO") & "_Year_" & Request.QueryString("year") & "_Q_" & Request.QueryString("q") & "_MERGE_DataCsv.csv"
strPathtoCSVFileTWO="Unit_" & Request.QueryString("XTNO") & "_Year_" & Request.QueryString("year") & "_Q_" & Request.QueryString("q") & "_MERGE_DataCsv_SORTED.csv"
Set Conn = CreateObject("ADODB.Connection")
Set RS = CreateObject("ADODB.Recordset")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPathtoCSVFolder & ";Extended Properties=""text;HDR=YES;FMT=Delimited"""
dim strDirInfoX
strDirInfoX="SELECT STATE, SUM(GALLONS) as Total FROM " & strPathtoCSVFile & " GROUP BY STATE "
'''''' response.write strDirInfoX
dim strTxttoMem
dim strsource
strsource="RS.Open " & strDirInfoX & " , Conn, 1, 3, &H0001"
RS.Open strsource
'response.write strsource
redim FieldNames(rs.fields.count)
redim FieldTypes(rs.fields.count)
For i = 0 To (rs.Fields.Count - 1)
FieldNames(i) = cstr(trim(rs.Fields.Item(i).Name))
FieldTypes(i) = cstr(trim(rs.Fields.Item(i).Type))
Next
RS.Close
RS.Open strDirInfoX, Conn, 3, 3, &H0001
Do Until RS.EOF
'''' for i=0 to ubound(FieldNames)-1
''' response.write(FieldNames(i) & " = " & RS.Fields.Item(FieldNames(i)) & "<br>")
strTxttoMem=strTxttoMem & RS("STATE") & RS("total")
'' next
RS.MoveNext
Loop
RS.Close
Conn.Close
dim fs,tfile
set fs=Server.CreateObject("Scripting.FileSystemObject")
set tfile=fs.CreateTextFile(strPathtoCSVFolder & strPathtoCSVFileTWO)
tfile.WriteLine(strTxttoMem)
tfile.close
set tfile=nothing
set fs=nothing
非常感謝你的幫助......
就是這樣......我簡直不敢相信。我花了超過4個小時的時間嘗試所有有用的東西,使其工作,這是一個「..再次感謝您的所有幫助 – compcobalt
嗯,它也適用於:」RS.Open「&strDirInfoX&」,康恩,1,3,&H0001 ....甜......很開心,你讓它爲我工作......感謝一百萬,你讓我的一天!這是肯定的。 – compcobalt
恭喜AutomatedChaos .. @compcobalt另一個建議..嘗試「設置RS = Conn.Execute(strDirInfoX)」,如果額外的參數是不必要的,節省了一些線條,並且更具可讀性 – peter