关于ASP成绩管理系统成绩数据批量录入问题
成绩输入部分:<% option explicit %>
<!-- #include file="connect.asp" -->
<script language="JavaScript">
<!--
function checkdata()
{
if(document.form1.cj.value=="")
{
alert("成绩不能为空,请输入成绩!");
document.form1.bj.focus();
return false;
}
return true;
}
//-->
</script>
<html>
<head>
<title>必修课成绩查询结果</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
.combox1 { height: 20px; width: 70px}
.f9 { font-family: "宋体"; font-size: 9pt}
-->
</style>
</head>
<%
dim xqh,bjdm,jsh,jsm,bjmc,kcdm,xh,kcmc,xm,xb,xq,recCnt
dim Sqla,rs,rb,sqlb
xqh=request("xq")
bjdm=request("bj")
kcdm=request("kc")
jsh=request("jsh")
'jsm=request("jsm")
'bjmc=request("bjmc")
'kcmc=request("kcmc")
Sqlb="select bjmc from class where bjdm='"& bjdm &"'"
set rb=adocon.execute(Sqlb)
'bjmc=rb("bjmc")
if rb.eof then
showerror("班级名称不存在,请重新输入!")
response.end
else
bjmc=rb("bjmc")
end if
dim n,k,m,g,tt
set rs=server.CreateObject("adodb.recordset")
Sqla="select kcmc,xh,xm, xb,bjmc,xq,jsm from view_yaoshucj where bjdm='"& bjdm &"' and xqh= '"& xqh &"' and kcdm='"& kcdm &"' and jsh='"& jsh &"'"
set rs=adocon.execute(sqla )
if rs.eof then
showerror("记录不存在,请重新输入!")
response.end
else
xh=rs("xh")
kcmc= rs("kcmc")
xb =rs("xb")
xm=rs("xm")
bjmc=rs("bjmc")
xq=rs("xq")
jsm=rs("jsm")
recCnt=rs.recordcount '获取记录总数目
end if
%>
<body bgcolor="#FFFFFF" topmargin="0">
<form name="form1" onSubmit="return checkdata()" action="cjcx_hsz_save.asp" method="post">
<table width="800" border="0" cellspacing="0" cellpadding="0" align="center"
style="BORDER-BOTTOM: #333333 1px solid; BORDER-LEFT: #333333 1px solid; BORDER-RIGHT: #333333 1px solid; BORDER-TOP: #333333 1px solid">
<tr bgcolor="#006699" align="left" height="31">
<td width="12%" ><font color="#FFFFFF" > 班级名: </font> </td>
<td width="24%" ><font color="#00FF00" ><%=bjmc%> </font></td>
<td width="12%" ><font color="#FFFFFF" > 教师名: </font> </td>
<td width="24%" ><font color="#00FF00" ><%=jsm%></font></td>
<td width="7%" ><font color="#FFFFFF" > 学期: </font> </td>
<td width="21%" ><font color="#00FF00" ><%=xq%></font></td>
</tr>
<tr bgcolor="#006699" align="left" height="31">
<td> <font color="#FFFFFF" > 考试性质:</font></td>
<td height="30" width="28%" align="center" >
<select name="ksxz" class="combox1" size="1" >
<option value=""></option>
<option value="-1" selected >考试</option>
<option value="-2">考查</option>
</select>
</td>
<td width="12%" ><font color="#FFFFFF" > 课程名称: </font> </td>
<td width="24%" ><font color="#00FF00" ><%=kcmc%></font></td>
<td width="12%" ><font color="#FFFFFF" > 学时: </font> </td>
<td width="24%" ><font color="#00FF00" ></font></td>
</tr>
</table>
<table width="800" border="0" cellspacing="1" cellpadding="1" align="center">
<tr bgcolor="#006699">
<td height="16" width="20%" align="center"><font color="#FFFFFF" >学号</font></td>
<td height="16" width="10%" align="center"><font color="#FFFFFF" >性别</font></td>
<td height="16" width="10%" align="center"><font color="#FFFFFF" >姓名</font></td>
<td height="16" width="20%" align="center"><font color="#FFFFFF" >成绩</font></td>
<td height="16" width="10%" align="center"><font color="#FFFFFF" >备注</font></td>
</tr>
<p>
<%
do while not rs.eof
'm=m-1
%>
<tr bgcolor="#f3f3f3">
<td height="16" width="20%" align="center"><font color="#000000" ><% =rs("xh") %></font></td>
<input type="hidden" name="xh" value=<% =rs("xh") %> >
<td height="16" width="10%" align="center" ><font color="#000000" ><% =rs("xb") %></font></td>
<input type="hidden" value=<% =rs("xb") %> name="xb">
<td height="16" width="10%" align="center" ><font color="#000000" ><% =rs("xm") %></font></td>
<input type="hidden" value=<% =rs("xm") %> name="xm">
<td height="16" width="15%" align="center"><p>
<input name="cj" type="text" value="" size="12"
onbeforepaste="clipboarddata.setdata('text',clipboarddata.getdata('text').replace(/[^\d]/g,''))"
onkeydown="subOnKeyDown()"
onkeyup="value=value.replace(/[^\d]/g,'')"/>
</td>
<td height="30" width="20%" align="center" >
<select name="flag" class="combox1" size="1" >
<option value=""></option>
<option value="0" selected >正常</option>
<option value="-1">旷考</option>
<option value="-2">缓考</option>
<option value="-3">作弊</option>
<option value="-4">取消</option>
<option value="-5">代考</option>
<option value="-6">重修</option>
<option value="-7">事假</option>
</select>
</td>
</tr>
<%
rs.movenext
loop
%>
</p>
</table>
<table width="800" border="0" cellspacing="0" cellpadding="0" align="center">
<tr><td height="53" colspan="5" align="center">
<input type="submit" value=" 确定 " name="action" action="cjcx_hsz_save.asp" method="post" ONCLICK="AlertButton()" >
</td></tr>
</table>
<input type="hidden" value=<% =kcdm %> name="kcdm">
<input type="hidden" value=<% =bjdm %> name="bjdm">
<input type="hidden" value=<% =bjmc%> name="bjmc">
</form>
</body >
<table width="500" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td height="84">
<div align="center"> <a href="javascript:history.go(-1)">返回</a></div>
</td>
</tr>
</table>
<span ><span > </span></span>
</body>
</html>
<script language="vbscript" runat="server">
sub showError(errorText)
response.write "<br>"
response.write "<table width=700 align=center>"
response.write "<tr><td><div align=center>"
response.write errorText
response.write "</div></td></tr>"
response.write "<tr><td><div align=center><br>"
response.write "<a href=javascript:history.go(-1)>"
response.write "返回>>"
response.write "</a>"
response.write "</div></td></tr></table>"
end sub
</script>
成绩保存部分:
<% option explicit %>
<!-- #include file="connect.asp" -->
<script language="vbscript" runat="server">
'向数据库写入数据
SUB writeData()
dim recCnt,i,sqlstr
dim xh,ksxz,xm,cj,hbh,jsh,bjdm,kcdm,flag,kslx
recCnt=request.form("xh").count '取得共有多少条记录
'批量录入数据
for i=1 to recCnt
xh=trim(request.form("xh")(i))
ksxz=trim(request.form("ksxz"))
cj=trim(request.form("cj")(i))
hbh=trim(request.form("hbh"))
jsh=trim(request.form("jsh"))
bjdm=trim(request.form("bjdm"))
kcdm=trim(request.form("kcdm"))
flag=trim(request.form("flag")(i))
sqlStr="insert into cjb(xh,ksxz,cj,hbh,jsh,bjdm,kcdm,flag) values('"
sqlStr=sqlStr & xh & "','"
sqlStr=sqlStr & ksxz & "','"
sqlStr=sqlStr & cj & "','"
sqlStr=sqlStr & hbh & "','"
sqlStr=sqlStr & jsh& "','"
sqlStr=sqlStr & bjdm & "','"
sqlStr=sqlStr & kcdm & "','"
sqlStr=sqlStr & flag & "')"
'response.write sqlStr
adocon.execute(sqlStr)
next
END SUB
</script>
<html>
<head>
<title>保存成绩</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF">
<%
if request.form("action")="提交" then
Call writeData() '向数据库批量写入数据
end if
%>
<table width="750" border="0" cellspacing="0" cellpadding="0" align="center">
<form name=form1 action="" method=post>
<input type="submit" name="action" value="提交" onClick="Call writeData()" >
</form>
</table>
</body>
</html>