论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > asp教程
Tag:入门,文摘,实例,技巧,iis,表单,对象,上传,数据库,记录集,session,cookies,存储过程,注入,分页,安全,优化,xmlhttp,fso,jmail,application,防盗链,stream,组件,md5,乱码,缓存,加密,验证码,算法,ubb,正则表达式,水印,,日志,压缩,url重写,控件,函数,破解,触发器,socket,ADO,初学,聊天室,留言本,视频教程

用数组实现数据记录的批量录入方法

文章类别:asp | 发表日期:2008-10-5 20:39:23

<%
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
视频教程列表
文章教程搜索
 
Asp推荐教程
Asp热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058