zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    C 习题
    gcc
    几何视角看线性方程组解的情况
    JAVA设计模式之工厂模式(简单工厂模式+工厂方法模式)
    为什么重写了equals(),还要重写hashCode()?
    关于ArrayList的越界问题?
    通过实例聊聊Java中的多态
    java异常处理实例分析
    Java: Integer用==比较时127相等128不相等的原因
    Java并发编程:Lock
  • 原文地址:https://www.cnblogs.com/daretodream/p/1723680.html
Copyright © 2011-2022 走看看