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

ContractedBlock.gifExpandedBlockStart.gif代码
<%
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; width:200px; height:30px;" ><%=title%></div></td><td ><div style="overflow:hidden; width:200px; height:30px;" ><%=pic%></div></td><td ><div style="overflow:hidden; width:200px; height:30px;" ><%=cate%></div></td>
<%
'next
%>
</tr>
<%
myNum
=myNum+1
Wend
myFile.Close
Set myFile = Nothing
Set Fso = Nothing
%
>
</table>

 

转载于:https://www.cnblogs.com/daretodream/archive/2010/04/29/1723680.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值