马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
×
<TABLE cellSpacing=0 cellPadding=0 width="100%" bgColor=#3060a0 border=0>
<TBODY>
<TR>
<TD vAlign=center align=middle width=589 bgColor=#4e4e4e height=25><FONT color=#ffffff><B>asp中利用数组实现数据库记录的批量录入方法</B></FONT></TD></TR>
<TR>
<TD vAlign=center align=middle height=38><FONT color=#ffffff>作者:yanek 来源:开发者俱乐部 加入时间:2002-12-12 蓝宝石软件站</FONT> </TD></TR>
<TR>
<TD vAlign=top height=48><FONT color=#ffffff>asp中利用数组实现数据库记录的批量录入方法(原创)<BR>演示:http://www.zwtd.com/1/yanek/n/needdj2.asp<BR><%<BR>rem 文章题目 asp中利用数组实现数据库记录的批量录入方法(原创)<BR>作者:yanek<BR>联系email:aspboy@263.net<BR>%><BR><BR>包括两个文件<BR>1。allneeddj.asp:实现表单的生成<BR>2. allneeddjresult.asp 处理表单批量录入<BR>3.hbedu.mdb :数据库文件<BR>其数据库结构如下<BR>provinceid:省份编号 数值型<BR>dytaocount:打样套数 数值型<BR>papertaocount:纸样套数 数值型<BR>cpcontent:出片内容 数值型<BR>filename:文件名 文本型<BR>beizhu:备注 备注型<BR><BR>本例子中以10条记录,每条记录6个字段说明.<BR><BR>1。allneeddj.asp<BR><BR><html><BR><BR><head><BR><meta http-equiv="Content-Language" content="zh-cn"><BR><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><BR><meta name="GENERATOR" content="Microsoft FrontPage 4.0"><BR><meta name="rogId" content="FrontPage.Editor.Document"><BR><title>需求登记</title><BR></head><BR><BR><body><BR><BR><BR><%<BR>set conn=server.createobject("adodb.connection")<BR>conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & _<BR>Server.MapPath("hbedu.mdb")<BR><BR>%><BR><BR><form method="OST" action="allneeddjresult.asp"><BR><div align="center"><BR><center><BR><table border="1" width="700" bordercolorlight="#FFFFFF"><BR><tr><BR><td width="660" colspan="6"><BR><p align="center">需求登记</td><BR></tr><BR><tr><BR><td width="54" align="center">省份</td><BR><td width="66" align="center">打样张数</td><BR><td width="66" align="center">纸样张数</td><BR><td width="66" align="center">出片内容</td><BR><td width="80" align="center">文件名</td><BR><td width="328" align="center"><BR><p align="center">备注</td><BR></tr><BR><BR><BR><%<BR>rem 通过循环动态生成不同名称表单域<BR>for i=1 to 10 <BR>%><BR><%<BR>set rs=server.createobject("adodb.recordset")<BR>sql="select * from provinceinfo "<BR>rs.open sql,conn,1,1<BR><BR><BR>set rs1=server.createobject("adodb.recordset")<BR>sql1="select * from filename "<BR>rs1.open sql1,conn,1,1<BR>%><BR><BR><BR><tr><BR><td width="54"><select name="<% response.write"data1"&i %>"<BR>size="1"><BR><%<BR>do while not rs.eof<BR>if province=cstr(rs("id")) then<BR>sel="selected"<BR>else<BR>sel=""<BR>end if <BR>response.write "<option " & sel & " value='"+CStr(rs("id"))+"'>"+rs("province")+"</option>"+chr(13)+chr(10)<BR>rs.movenext<BR>loop<BR>set rs=nothing<BR>%> </select></td><BR><td width="66"><input type="text" name="<% response.write"data2"&i %>" size="8"></td><BR><td width="66"><input type="text" name="<% response.write"data3"&i %>" size="8"></td><BR><td width="66"><select size="1" name="<% response.write"data4"&i %>"><BR><option value="1">改动部分</option><BR><option value="2">全部内容</option><BR></select></td><BR><td width="80"><select name="<% response.write"data5"&i %>"<BR>size="1"><BR><%<BR>do while not rs1.eof<BR>if filename=cstr(rs1("filename")) then<BR>sel="selected"<BR>else<BR>sel=""<BR>end if <BR>response.write "<option " & sel & " value='"+CStr(rs1("filename"))+"'>"+rs1("filename")+"</option>"+chr(13)+chr(10)<BR>rs1.movenext<BR>loop<BR><BR>set rs1=nothing<BR>%> </select> </td><BR><td width="328"><textarea rows="2" name="<% response.write"data6"&i %>" cols="46"></textarea></td><BR></tr><BR><BR><BR><BR><% next %><BR><BR><BR><BR><tr><BR><td width="660" colspan="6"><BR><p align="center"><input type="submit" value="提交" name="B1"></td><BR></tr><BR></table><BR></center><BR></div><BR></form><BR><BR></body><BR><BR></html><BR><BR>2.allneeddjresult.asp<BR><BR><BR><%<BR>rem 定义二维数组存放从表单获取的值<BR>dim data(10,6)<BR>for i= 1 to 6<BR>for j= 1 to 10<BR>mydata="data"+cstr(i)+cstr(j)<BR>data(j,i)=request.form(mydata)<BR>next<BR>next<BR>%><BR><BR><%<BR>rem 输出表单输入的值<BR>for i= 1 to 10<BR>for j= 1 to 6<BR><BR>response.write data(i,j)<BR><BR>next<BR>response.write"<br>"<BR>next<BR><BR>'response.end<BR>%><BR><BR><% <BR>dim conn,rs<BR>Set conn = Server.CreateObject("ADODB.Connection")<BR>conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & _<BR>Server.MapPath("hbedu.mdb")<BR><BR><BR>for i= 1 to 10<BR>rem 循环批量入库<BR><BR>Set rs=SERVER.CreateObject("ADODB.Recordset")<BR>rs.Open "hbedu",conn,1,3<BR>rs.AddNew<BR>rs("beizhu")=data(i,6)<BR>rs("filename")=data(i,5)<BR>rs("cpcontent")=data(i,4)<BR>rs("papertaocount")=data(i,3)<BR>rs("dytaocount")=data(i,2)<BR>rs("provinceid")=data(i,1)<BR>rs.Update<BR>rs.close<BR>set rs=nothing<BR><BR>response.write"ok<br>"<BR>next<BR>%><BR>演示:http://www.zwtd.com/1/yanek/n/needdj2.asp<IMG height=1 src="http://soft.bluejewel.net/down_info.asp?id=42" width=1 border=0><BR></FONT></TD></TR></TBODY></TABLE> |