以下为引用的内容:
<% ’向数据库写入数据 SUB writeData() dim recCnt,i dim fieldName1,fieldName2,fieldName3 dim conn dim sqlStr,connStr connStr="Provider=SQLOLEDB.1;Initial Catalog=myDatabase;Data Source=myhon;User Id=sa;PASSWORD=" set conn=Server.CreateObject("ADODB.Connection") conn.open connStr ’建立数据库连接 recCnt=request.form("stu_num").count ’取得共有多少条记录 ’批量录入数据 for i=1 to recCnt fieldName1=trim(request.form("fieldName1")(i)) fieldName2=trim(request.form("fieldName2")(i)) fieldName3=trim(request.form("fieldName3")(i)) sqlStr="insert into myTable(fieldName1,fieldName2,fieldName3) values(’" sqlStr=sqlStr & fieldName1 & "’,’" sqlStr=sqlStr & fieldName2 & "’,’" sqlStr=sqlStr & fieldName3 & "’)" ’response.write sqlStr conn.execute(sqlStr) next END SUB ’显示成批录入的界面 SUB InputData() dim recCnt,i %> <form name="bathInputData" action="" method="post"> <% recCnt=cint(request.form("recCnt")) for i=1 to recCnt %> <input type="text" name="fieldName1"> <input type="text" name="fieldName2"> <input type="text" name="fieldName3"> <% next %> <br> <input type="submit" name="action" value="提交"> </form> <% END SUB ’指定要批量录入多少条记录 SUB assignHowMuch() %> <!------指定要录入多少条记录--------------> <form name="form1" 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 %> |