日期:2014-05-17  浏览次数:21080 次

如何实现批量录入粘帖文本内容~【高难度】
复制规定格式的文本文件,如:

卡号   密码   面值   价格

001   123   30   10
002   122   30   10
003   111   50   12

数字之间用空格或者其他符号隔开,每一行为一条数据

如何把以上数据批量录入到数据库里呢?



------解决方案--------------------
av=1
for e=1 To 3
xwzw=trim(request.Form( "xwzw "&e))
xwdy=trim(request.Form( "xwdy "&e))
kysbsj=trim(request.Form( "kysbsj "&e))
if xwdy= " " then
xwdy= "  "
end if
if kysbsj= " " then
kysbsj= "  "
end if
set eers=server.CreateObject( "adodb.recordset ")
if xwzw <> " " then
eers.open "select * from vipqzyx ",conn,1,3 '/////////////求知意向信息的录入
av=av+1
eers.addnew
eers( "ClubId ")=ClubId
eers( "xwzw ")=xwzw
eers( "xwdy ")=xwdy
eers( "kysbsj ")=kysbsj
eers.update
end if
next
------解决方案--------------------
客户端
<html>
<body>

<form name= "form1 " action= "c7.asp " method= "post ">
<textarea rows= "20 " cols= "48 " name= "data "> </textarea>
分隔符 <input type= "text " name= "spliter " size= "2 ">
<input type= "submit ">
</form>
</body>
</html>

服务器端 c7.asp

<%
spliter = Request.Form( "spliter ")
If spliter = " " Then spliter = " "
data = Trim(Request.Form( "data "))
lines = split(data,VbCrLf)

Dim aFlds(3), aVals(3)
'修改数据库的字段
aFlds(0) = "卡号 "
aFlds(1) = "密码 "
aFlds(2) = "面值 "
aFlds(3) = "价格 "

'修改数据库链接串
sConn = "Provider=SQLOLEDB;Data source=127.0.0.1;Initial Catalog=eam;User ID=sa;Password=; "
Set oCnn = CreateObject( "ADODB.Connection ")
oCnn.Open sConn
Set oRS = CreateObject( "ADODB.RecordSet ")
With oRS
.cursorLocation = 3
.open "SELECT [卡号], [密码], [面值], [价格] FROM card WHERE 1=0 ", oCnn, 1,4
For i=0 To UBound(lines)
lines(i) = Trim(lines(i))
If lines(i) <> " " Then
arr = Split(lines(i), spliter)
If UBound(arr)> 2 Then
aVals(0) = arr(0)
aVals(1) = arr(1)
aVals(2) = arr(2)
aVals(3) = arr(3)
.AddNew aFlds, aVals
End If
End If
Next
.UpdateBatch
End With

Set oRS = Nothing
Set oCnn = Nothing

Response.Write "OK "
%>