用數組實現資料記錄的批量錄入方法

來源:互聯網
上載者:User
<%
rem 文章題目 asp中利用數組實現資料庫記錄的批量錄入方法(原創)
作者:yanek
聯絡email:aspboy@263.net
%>

包括兩個檔案
1。allneeddj.asp:實現表單的產生
2. allneeddjresult.asp 處理表單批量錄入
3.hbedu.mdb :資料庫檔案
其資料庫結構如下
provinceid:省份編號 數值型
dytaocount:打樣套數 數值型
papertaocount:紙樣套數 數值型
cpcontent:出片內容 數值型
filename:檔案名稱 文本型
beizhu:備忘  備忘型

本例子中以10條記錄,每條記錄6個欄位說明.

1。allneeddj.asp

<html>

<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>需求登記</title>
</head>

<body>



<%
set conn=server.createobject("adodb.connection")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & _
             Server.MapPath("hbedu.mdb")

%>

<form method="POST" action="allneeddjresult.asp">
  <div align="center">
    <center>
  <table border="1" width="700" bordercolorlight="#FFFFFF">
    <tr>
      <td width="660" colspan="6">
        <p align="center">需求登記</td>
    </tr>
    <tr>
      <td width="54" align="center">省份</td>
      <td width="66" align="center">打樣張數</td>
      <td width="66" align="center">紙樣張數</td>
      <td width="66" align="center">出片內容</td>
      <td width="80" align="center">檔案名稱</td>
      <td width="328" align="center">
        <p align="center">備忘</td>
    </tr>
    
    
    <%
rem 通過迴圈動態產生不同名稱表單域
for i=1 to 10
%>
    <%
    set rs=server.createobject("adodb.recordset")
sql="select * from provinceinfo "
rs.open sql,conn,1,1



set rs1=server.createobject("adodb.recordset")
sql1="select * from filename "
rs1.open sql1,conn,1,1
    %>
    
    
    <tr>
      <td width="54"><select name="<% response.write"data1"&i %>"
      size="1">
<%
              do while not rs.eof
                             if province=cstr(rs("id")) then
                                sel="selected"
                             else
                                sel=""
                             end if            
                             response.write "<option " & sel & " value='"+CStr(rs("id"))+"'>"+rs("province")+"</option>"+chr(13)+chr(10)
                     rs.movenext
                   loop
                   set rs=nothing
              %>      </select></td>
      <td width="66"><input type="text" name="<% response.write"data2"&i %>" size="8"></td>
      <td width="66"><input type="text" name="<% response.write"data3"&i %>" size="8"></td>
      <td width="66"><select size="1" name="<% response.write"data4"&i %>">
          <option value="1">改動部分</option>
          <option value="2">全部內容</option>
        </select></td>
      <td width="80"><select name="<% response.write"data5"&i %>"
      size="1">
<%
              do while not rs1.eof
                             if filename=cstr(rs1("filename")) then
                                sel="selected"
                             else
                                sel=""
                             end if            
                             response.write "<option " & sel & " value='"+CStr(rs1("filename"))+"'>"+rs1("filename")+"</option>"+chr(13)+chr(10)
                     rs1.movenext
                   loop
                   
                       set rs1=nothing
              %>      </select> </td>
      <td width="328"><textarea rows="2" name="<% response.write"data6"&i %>" cols="46"></textarea></td>
    </tr>
  
    
    
      <% next %>
    
    
    
    <tr>
      <td width="660" colspan="6">
        <p align="center"><input type="submit" value="提交" name="B1"></td>
    </tr>
  </table>
    </center>
  </div>
</form>

</body>

</html>

2.allneeddjresult.asp


<%
rem 定義二維數組存放從表單擷取的值
dim data(10,6)
for i= 1 to 6
for j= 1 to 10
mydata="data"+cstr(i)+cstr(j)
data(j,i)=request.form(mydata)
next
next
%>

<%
rem 輸出表單輸入的值
for i= 1 to 10
for j= 1 to 6

response.write data(i,j)

next
response.write"<br>"
next

'response.end
%>

<%
dim conn,rs
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & _
             Server.MapPath("hbedu.mdb")


for i= 1 to 10
rem 迴圈批量入庫

Set rs=SERVER.CreateObject("ADODB.Recordset")
rs.Open "hbedu",conn,1,3
  rs.AddNew
  rs("beizhu")=data(i,6)
  rs("filename")=data(i,5)
  rs("cpcontent")=data(i,4)
  rs("papertaocount")=data(i,3)
  rs("dytaocount")=data(i,2)
  rs("provinceid")=data(i,1)
  rs.Update
rs.close
set rs=nothing

response.write"ok<br>"
next
%>
示範:http://www.zwtd.com/1/yanek/n/needdj2.asp


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.