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>
  • 相关阅读:
    SQL中的max()函数用法
    C#多线程
    C#操作redis
    spring+mybatis 多数据库事务
    实战项目中 :一个业务对多个数据库操作的同步的处理办法(要么都成功,要么都失败)Threadlocal 数据库事务
    redis之数据操作详解
    C# 两个数组取交集/补集 Intersect()
    MySQL创建索引
    MySQL每日执行
    MySQL删除重复数据
  • 原文地址:https://www.cnblogs.com/daretodream/p/1723680.html
Copyright © 2011-2022 走看看