<%@ Page Language="vb" Debug="true" %>
<%@ import namespace="system.data.oledb" %>
<script language="VB" runat=server>
dim cmd as oledbcommand
dim dr as oleDbDataReader
dim sql as string
dim selLesson as string
sub page_load(s as object,e as eventargs)
selLesson=request.querystring("selLesson")
dim title as string,i as integer
dim conn as oledbconnection
conn=new oledbconnection(configurationsettings.appsettings("strconn"))
conn.open()
sql="select * from asp" & selLesson & " order by 题号"
cmd=new oledbcommand(sql,conn)
dr=cmd.executereader()
while dr.read()
dim literal1 as new literalcontrol
dim literal2 as new literalcontrol
dim rlist
if dr.item("类型")="选择"then
rlist=new radiobuttonlist
else
rlist=new checkboxlist
end if
literal1.text="<b>" & dr.item("题号") & "."
literal1.text & =server.htmlencode(dr.item("题目"))
literal1.text & ="(" & dr.item("类型")& ":"
literal1.text & =dr.item("分数") & "分)</b><blockquote>"
literal2.text ="</blockquote>"
for i=1 to 4
rlist.items.add(server.htmlencode(Dr.item("选项"&i)))
rlist.items(i-1).value=i
next
mypanel.controls.add(literal1)
mypanel.controls.add(rlist)
myPanel.controls.add(literal2)
end while
dr.close()
conn.close()
end sub
sub score_click(sender as object, e as eventargs)
sellesson=request.querystring("sellesson")
dim conn as oledbconnection
conn=new oledbconnection(configurationsettings.appsettings("strconn"))
conn.open()
sql="select * from [asp]" & selLesson & "order by 题号"
cmd=new oledbcommand(sql,conn)
dr=cmd.executereader()
dim i,k,getscore as integer,answer as string
while dr.read()
answer=""
i=dr.item("题号")
dim list as listcontrol=mypanel.controls(1+3*(i-1))
if dr.item("类型")="选择" then
if not list.selecteditem is nothing then
answer=list.selecteditem.value
end if
else
for k=0 to list.items.count - 1
if list.items(k).selected then
if answer="" then
answer=list.items(k).value
else
answer &="," & list.items(k).value
end if
end if
next
end if
if answer=dr.item("解答") then getscore += dr.item("分数")
end while
dr.close()
sql="update 成绩 set " & sellesson & "=" & getscore.tostring() & "where 学号=" & "'" & request("noid") & ""
cmd=new oledbcommand(sql,conn)
cmd.executenonquery()
conn.close()
response.redirect("score.aspx?学号=" & request("noid"))
end sub
</script>
<html>
<head><title>网上考试</title></head>
<body bgcolor="#eeccff">
<form runat="server">
<center><cont size="6"><%=request("sellesson2")%>ASP试题</font></center><hr color="blue">
<blockquote>
<asp:panel runat="server" id ="mypanel"/>
</blockquote>
<asp:linkbutton runat="server" text="交卷" onclick="score_click"/>
</blockquote>
</form>
</body>
</html>
6 个解决方案
#1
" & selLesson & "
里是啥。
里是啥。
#2
这是考试页面预提交的网页,有数据库,在提交页面的时候有错误
#3
看你生成的SQL 是啥样的。
#4
课程变量
#5
那你生成的SQL 可以在查询分析器里跑?
#1
" & selLesson & "
里是啥。
里是啥。
#2
这是考试页面预提交的网页,有数据库,在提交页面的时候有错误
#3
看你生成的SQL 是啥样的。
#4
课程变量
#5
那你生成的SQL 可以在查询分析器里跑?
#6
楼主还是使用一个数据框架来做好些,可以少些很多代码,甚至SQL都不用写,例如
PDF.NET框架,通过配置能够生成SQL日志。