答案: 当我们有时在添加新记录时,一次添加一条的操作很不方便,尤其是在录入大批量的数据时,比如:学生成绩。
下面是我给一个客户做的自定义添加记录数(即:用户可以自己选择当前一次添加多少条记录),并用vb函数对每个需要输入的文本框做了检查。
下面是源程序:
<%@ Language=VBScript %>
<%
'文件名:dd_product_price.asp
'功能:添加商品价格详细资料
'说明:后台程序
'程序:小白
'时间:2002-5-15
'更新:
'更新说明:
'公司:坐标公司
'主页:www.zbhn.com
%>
<HTML>
<HEAD>
<title> <%=application("web_name")%> --->添加商品价格资料</title>
<META NAME="GENERATOR" Content="Microsoft FrontPage 4.0">
<style type="text/css"> <!-- a:link {color:darkslateblue;text-decoration:none}
a:visited {color:darkslateblue;text-decoration:无}
a:hover {color:brown;text-decoration:底线}
input.radio {background: navyblue; color:#000000}
font { font-size: 9pt; line-height: 13pt; FONT-FAMILY:MS Shell Dlg,Tahoma}
td { font-size: 9pt; line-height: 13pt; FONT-FAMILY:MS Shell Dlg,Tahoma}
textarea { BACKGROUND-COLOR: #e8e8e8; BORDER-BOTTOM: 1px double; BORDER-LEFT: 1px double; BORDER-RIGHT: 1px double; BORDER-TOP: 1px double; COLOR: #000000;; font-size: 9pt ;FONT-FAMILY:MS Shell Dlg,Tahoma}
input { BACKGROUND-COLOR: #e8e8e8; BORDER-BOTTOM: 1px double; BORDER-LEFT: 1px double; BORDER-RIGHT: 1px double; BORDER-TOP: 1px double; COLOR: #000000;; font-size: 9pt; FONT-FAMILY:"MS Shell Dlg", "Tahoma"; background-position: center}
--></style>
<SCRIPT LANGUAGE="javascript" src="js/refuse_visit.js"></SCRIPT>
<SCRIPT LANGUAGE="javascript" src="js/max_window.js"></SCRIPT>
</HEAD>
<body>
<!--#include file="sjkpzwj/ytxx_conn.inc"-->
<p align="center">
<%
dim url
url=request.ServerVariables("SCRIPT_NAME")
on error resume next
record=request.QueryString("record")
if record="" then
record=1
end if
record=cint(record)
if Err.number <> 0 then
record=1
Response.Write "操作不当,请下次小心点"
end if
if Request.ServerVariables ("Request_Method")="POST" then
'如果提交过来的是post方法,则添加记录到数据库
dim text1(20),text2(20),text3(20),text4(20)
'______________________
sub gave_value(text,xx)
on error resume next
count=0
for each item in Request.Form(text)
xx(count)=item
count=count+1
next
if Err.number <> 0 then
response.Write "sub err:"& Err.Description
end if
end sub
on error resume next
'____________________
call gave_value("text1",text1)
call gave_value("text2",text2)
call gave_value("text3",text3)
call gave_value("text4",text4)
if Err.number <> 0 then
response.Write "call sub err:"&Err.Description
end if
'%%%%%%%%%%%%%%%%%%%%%%%%
on error resume next
if Err.number <> 0 then
response.Write "show text1 err:"&Err.Description
Response.End
end if
'%%%%%%%%%%%%%%%%%%
%>
<center>添加商品价格资料 </center>
<%
set Rs=server.CreateObject ("ADODB.Recordset")
on error resume next
Rs.Open "select * from price where 1=2",str_connection,1,3
'************************************
if Err.number <> 0 then
Response.Write "Error---><br>"&Err.Description &"<br><font color=red>;Please contact with the <font color=red> web master</font>!</font>"
Rs.Close
set Rs=nothing
Response.End
end if
'**************************************
'连接数据库、打开数据表成功后
'______使用addnew方法添加记录________
on error resume next
for jj=0 to record-1
Rs.AddNew
rs(1)=text1(jj)
rs(2)=text2(jj)
rs(3)=text3(jj)
rs(4)=text4(jj)
Rs.Update
next
Rs.Close
set Rs=nothing
if Err.number <> 0 then
'如果提交失败
Response.Write &
上一个:把文件存进access数据库然后取出来供人下载的代码(取自e-office部分模块)
下一个:谈谈我对截取一定长度字符串的一点心得,欢迎指正