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

高分悬赏,ASP中一次性插入10行数据
各位高手,请问如何在ASP中一次性插入10行数据,结构如下:

音乐         艺术           政治


我每次只能插入一条提交之后才能再插入第二次

------解决方案--------------------
asp动态代码
你对着自己的数据库改改吧!^_^

<%
'#####################################
'File Function:批量录入数据
'Author:Myhon
'Date:2003-8-19
'#####################################

'向数据库写入数据
SUB writeData()
dim recCnt,i
dim UserID,UserName,score
dim conn
dim sqlStr,connStr
connStr= "driver={Microsoft Access Driver (*.mdb)};DefaultDir=;dbq= "2.mdb "

set conn=Server.CreateObject( "ADODB.Connection ")
conn.open connStr '建立数据库连接

recCnt=cint(request.form( "recCnt ")) '取得共有多少条记录
'批量录入数据
for i=1 to recCnt
UserID=trim(request.form( "UserID ")(i))
UserName=trim(request.form( "UserName ")(i))
score=trim(request.form( "score ")(i))
sqlStr= "insert into Users(UserID,UserName,score) values( ' "
sqlStr=sqlStr & UserID & " ', ' "
sqlStr=sqlStr & UserName & " ', ' "
sqlStr=sqlStr & score & " ') "
response.write sqlStr
conn.execute(sqlStr)
next
conn.close
response.write "数据已经成功录入!谢谢使用! "
END SUB

'显示成批录入的界面
SUB InputData()
dim recCnt,i
%>
<form name= "bathInputData " action= " " method= "post ">
<%
recCnt=cint(request.form( "recCnt "))
for i=1 to recCnt
%>
录入第 <%=i%> 条记录 <br>
用户名: <input type= "text " name= "UserID ">
名字: <input type= "text " name= "UserName ">
成绩: <input type= "text " name= "score ">
<br>
<%
next
%>
<input type= "hidden " name= "recCnt " value= " <%=recCnt%> ">
<input type= "submit " name= "action " value= "提交 ">
</form>
<%
END SUB

'指定要批量录入多少条记录
SUB assignHowMuch()
%>
<!------指定要录入多少条记录-------------->
<form name= "stu_num " action= " " method= "post ">
您要录入的记录的条数: <input type= "text " name= "recCnt ">
<input type= "submit " name= "action " value= "下一步> > ">
</form>
<%
END SUB

if request.form( "action ")= "下一步> > " then
Call InputData() '显示成批录入界面
elseif request.form( "action ")= "提交 " then
Call writeData() '向数据库批量写入数据
else
Call assignHowMuch() '显示指定录入多少条记录的界面
end if

%>