• ASP读取CSV文件 并添加到数据库


    代码
    <%
    set conn=Server.CreateObject("ADODB.Connection")
    conn.Provider
    ="Microsoft.Jet.OLEDB.4.0"
    dbpath
    =Server.MapPath("qipu.mdb")
    conn.Open dbpath
    strFileName
    = Request.QueryString("file1")
    set rs = Server.CreateObject("ADODB.recordset")
    Dim Fso
    Dim myFile
    Dim titleindex
    Dim cateindex
    Dim picindex
    Dim detailindex
    dim arr()
    Set Fso = Server.CreateObject("Scripting.FileSystemObject")
    Set myFile = Fso.OpenTextFile(Server.MapPath("1111.csv"),1,True,-1)
    'A.TXT和ASP程序在同个目录下,如果没在一个目录,可以用绝对路径,把上一行的a.txt改为:d:\a.txt
    %>
    <table border="1">
    <%
    myNum
    =0
    While Not myFile.AtEndOfStream
    If myNum = 0 Then
    row
    =Split(myFile.ReadLine," ")
    for i=0 to ubound(row)
    MyVar
    =row(i)
    Select Case MyVar
    Case "宝贝名称" titleindex= i
    Case "宝贝类目" cateindex=i
    Case "新图片" picindex=i


    End Select
    next
    End If

    row
    =Split(myFile.ReadLine," ")
    %
    >
    <tr>
    <%
    'for i=0 to ubound(row)
    '
    td=row(i)
    title=row(titleindex)
    pic
    =row(picindex)
    cate
    =row(cateindex)
    sql
    ="insert into product(title,pic,cate) values('"&title&"','"&pic&"','"&cate&"')"
    rs.Open sql, conn

    %
    >
    <td ><div style="overflow:hidden; 200px; height:30px;" ><%=title%></div></td><td ><div style="overflow:hidden; 200px; height:30px;" ><%=pic%></div></td><td ><div style="overflow:hidden; 200px; height:30px;" ><%=cate%></div></td>
    <%
    'next
    %>
    </tr>
    <%
    myNum
    =myNum+1
    Wend
    myFile.Close
    Set myFile = Nothing
    Set Fso = Nothing
    %
    >
    </table>
  • 相关阅读:
    CodeForces 825G"Tree Queries"(选根建树)
    技术日记
    [express.js 使用笔记] ajax询问数据,却显示在浏览器上,该怎么办?
    node.js 基础和文件操作 笔记
    JSON 笔记
    CSS 学习笔记(一)选择器
    cf1321E
    [学习笔记] 后缀数组
    Python 编程练习
    《明朝那些事儿》 读书笔记
  • 原文地址:https://www.cnblogs.com/daretodream/p/1723680.html
Copyright © 2020-2023  润新知