English 中文(简体)
阅读 CSV 在唱片?
原标题:Reading CSV in Recordset?

首先,请允许我说,我非常愿意在需要帮助时,在需要帮助提供代码方面有一个地方可以去。 当我看到有人试图提供帮助时,我甚至更感感谢。 因此,在座的各位都感谢你们看我的问题/问题,即使你们没有答案。

因此,关于我的问题/问题:

我试图让这工作, 但我似乎找不到语法错误!

谁能帮帮我...

这是代码:

dim strPathtoCSVFolder,strPathtoCSVFile,strPathtoCSVFileTWO

strPathtoCSVFolder="D:classic_asp	est" & 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

非常感谢你的帮助...

最佳回答

好吧,没有运行您的代码, 我发现了一个错误 在这部分:

dim strsource 
strsource="RS.Open " & strDirInfoX & " , Conn, 1, 3, &H0001" 
RS.Open strsource 

或缩短它,你们就这样做了:

RS.Open "RS.Open " & strDirInfoX & " , Conn, 1, 3, &H0001" 

更改为 RS. Open strDirInfoX, Conn, 1, 3, & amp; H0001 , 而这部分运行会更好 。

问题回答

这几乎不可能回答,可能存在多重错误,而且很大程度上取决于以前宣布的内容,例如,一个明确选项会产生巨大的差别(而且可取)。

Since debugging in the browser is difficult at best, you copy this code - that comes from an asp file i guess - and put it in a vbs script, replace the response.write with wscript.echo and run the code. Then you get an error at some line, correct it and so on, afterward replace the echos s by response.write s and you r done.

我建议使用 Firefox 和 Firebug 插件来进行测试, 您将会获得更多调试信息, 至少使用铬或 IE 中的开发器视图

成功... 成功...

在VBScript上工作了一段时间,但不应该归档。 关闭是tfile。 关闭吗?

您是否尝试将文件作为文本文件阅读, 而不是连接到 ADODB 连接的文件? 由于它是一个 CSV 文件, 您也许可以将它作为纯文本文件阅读 。 您可以将内容与逗号和环分割开来, 并获得您想要的内容 。

如果您想要使用 ADODB 连接访问它, 请尝试用 xlsx 范围化保存文件( 通过代码复制内容, 或者手动保存它。 同样的代码可能有效 ) 。

毫无羞耻地为我的博客“ADO”添加一个链接。

http://www.blogger.com/blogger.g?blogID=303301486958588885023#editor/targ=post;postID=82741193425509092





相关问题
How to import excel file in web page useing Classic ASP?

We are trying to open an existing excel file (2003) from server location in a web page and save it again in the same location using following syntax. Set ExcelReportApp = CreateObject("Excel....

What s the best method to do paging in my ASP page

What s the best method to do paging in my ASP page when displaying a list of items? I knew that there is no equivalent to MySQL s LIMIT clause present in SQL Server, either 2000 or 2005. How can I ...

Using Classes in a Dictionary in Classic ASP

I usually do C# but have inherited a classic ASP project. I have defined a class: Class clsPayment Public Name End Class Set objPayment = New clsPayment objPayment.Name = "...

Response.Redirect HTTP status code

Why is it that ASP/ASP.NET Response.Redirect uses a HTTP-302 status code ("Moved Temporarily") even though in most cases a HTTP-301 status code ("Moved Permanently") would be more appropriate?

form inside form serialize problem

I am trying to submit a form inside another form because I will need first form s outcome in the second form. I tried using form serialize as advised in some other threads. Problem here is, I dont ...

热门标签