asp實現批量錄入資料

來源:互聯網
上載者:User

請看如下原始碼:

<%
'向資料庫寫入資料
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
%>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.