<%@ import namespace="system.data" %>
<%@ 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 subsub 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主要解决数据更新的问题
数据库名etest
表名 asp,英语,vb,java,asp,操作系统,成绩表
asp ,英语,vb,java,操作系统 表结构
题号,题目,类型,分数,选项1,选项2,选项3,选项4,解答,分数(未考)
成绩表结构
学号,姓名,密码,英语,vb,java,asp,操作系统
</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>web.config文件
<configuration>
<system.web>
<authentication mode="Forms">
<forms name="authCokie" loginUrl="login\kaoshi1.aspx"/>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
<location path="log">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
<location path="admin">
<system.web>
<authorization>
<allow users="admin"/>
<deny uses="*"/>
</authorization>
</system.web>
</location>
<appSettings>
<add key="strcon" value="provider=microsoft.jet.oledb.4.0; data source=D:\kaoshi\etest.mdb"/>
</appSettings>
</configuration>
登陆文件
<%@ import namespace="system.data.oledb"%>
<script language="vb" runat="server">
Sub page_load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
message2.Text = CStr(Int(9 * Rnd())) & CStr(Int(9 * Rnd())) & CStr(Int(9 * Rnd())) & CStr(Int(9 * Rnd()))
End If
end sub
sub login(sender as object, e as eventargs)
dim username as string =txtname.text
dim userpass as string=txtpass.text
Dim yanzheng as String = t1.Text
if not username ="" and not userpass ="" And yanzheng = message2.Text then
message.text=checkuser(username,userpass)
if message.text="ok" then
response.redirect("..\huanying.aspx")
session("username")=username
response.redirect("resister.aspx")
end if
ElseIf yanzheng <> message2.Text Then
message2.Text = CStr(Int(9 * Rnd())) & CStr(Int(9 * Rnd())) & CStr(Int(9 * Rnd())) & CStr(Int(9 * Rnd()))
message.Text = "请输入正确的验证信息"
yanzheng = ""
else
message2.Text = CStr(Int(9 * Rnd())) & CStr(Int(9 * Rnd())) & CStr(Int(9 * Rnd())) & CStr(Int(9 * Rnd()))
message.text="请输入完整的信息"
end if
end sub
sub zhuce(sender as object, e as eventargs)
response.redirect("resister.aspx")
end sub
function checkuser(byval n as string, byval p as string) as string
dim strcon as string
strcon="provider=microsoft.jet.oledb.4.0;data source=" & server.mappath("..\etest.mdb")
dim conn as new oledbconnection(strcon)
dim strsql as string ="select * from 成绩表 where [学号]='"+n+"' and [密码]='"+p+"'"
conn.open()
dim cmd as new oledbcommand(strsql,conn)
dim dr as oledbdatareader=cmd.executereader()
if dr.read() then
return "ok"
else
return "c"
end if
conn.close()
end function
</script>
<html>
<body ><center><h2>用户登录</h2>
<hr>
<form id="form1" method="post" runat="server">
学 号: <asp:textbox id="txtname" size="17" runat="server"/>
<br>
密 码: <asp:textbox id="txtpass" size="19" textmode="password" runat="server"/><br>验证码: <asp:textbox id="t1" size="6" runat=server />
<asp:label id="message2" size="8" runat=server /> <br>
<asp:button id="button1" text="登录" onclick="login" runat="server"/> <asp:linkbutton text="注册" onclick="zhuce" runat="server"/><br>
<asp:label id="message" runat="server"/>
</form></center>
</body>
</html>注册的
<html>
<body><center>
<h2> 用户注册</h2>
<hr>
<form id="form1" runat="server">
姓   名:<asp:textbox id="txtname" size="17" runat="server"/><br>
密   码:<asp:textbox id="txtpass" size="19" textmode="password" runat="server"/><br>
学   号:<asp:textbox id="txtnum" size="17" runat="server"/><br><asp:button text="注册" onclick="reg" runat="server" id="button1"/><br>
<font color="red">
<asp:label id="message" runat="server"/></font>
</form></center>
</body>
</html>
<%@ import namespace="system.data.oledb"%>
<script language="vb" runat="server">
sub reg(sender as object,e as eventargs)
dim username as string=txtname.text
dim userpass as string=txtpass.text
dim usernum as string=txtnum.text
if not username="" and not userpass="" and not usernum="" then
message.text=saveuser(username,userpass,usernum)
if message.text="ok" then
session("username")=username
response.redirect("login.aspx")
end if
else
message.text="请输入完整的信息"
end if
end sub
function saveuser(byval n as string,byval p as string,byval m as string) as string
dim strcon as string="provider=microsoft.jet.oledb.4.0;data source=" & server.mappath("..\eTest.mdb")
dim conn as new oledbconnection(strcon)
dim strsql as string="insert into 成绩表([姓名],[密码],[学号]) values ('"+n+"','"+p+"','"+m+"')"
conn.open()
dim cmd as new oledbcommand(strsql,conn)
try
cmd.executenonquery()
return "ok"
catch ex as exception
return "注册出错,请联系管理员"+ex.tostring
end try
conn.close()
end function
</script>
<%@ 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 subsub 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主要解决数据更新的问题
数据库名etest
表名 asp,英语,vb,java,asp,操作系统,成绩表
asp ,英语,vb,java,操作系统 表结构
题号,题目,类型,分数,选项1,选项2,选项3,选项4,解答,分数(未考)
成绩表结构
学号,姓名,密码,英语,vb,java,asp,操作系统
</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>web.config文件
<configuration>
<system.web>
<authentication mode="Forms">
<forms name="authCokie" loginUrl="login\kaoshi1.aspx"/>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
<location path="log">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
<location path="admin">
<system.web>
<authorization>
<allow users="admin"/>
<deny uses="*"/>
</authorization>
</system.web>
</location>
<appSettings>
<add key="strcon" value="provider=microsoft.jet.oledb.4.0; data source=D:\kaoshi\etest.mdb"/>
</appSettings>
</configuration>
登陆文件
<%@ import namespace="system.data.oledb"%>
<script language="vb" runat="server">
Sub page_load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
message2.Text = CStr(Int(9 * Rnd())) & CStr(Int(9 * Rnd())) & CStr(Int(9 * Rnd())) & CStr(Int(9 * Rnd()))
End If
end sub
sub login(sender as object, e as eventargs)
dim username as string =txtname.text
dim userpass as string=txtpass.text
Dim yanzheng as String = t1.Text
if not username ="" and not userpass ="" And yanzheng = message2.Text then
message.text=checkuser(username,userpass)
if message.text="ok" then
response.redirect("..\huanying.aspx")
session("username")=username
response.redirect("resister.aspx")
end if
ElseIf yanzheng <> message2.Text Then
message2.Text = CStr(Int(9 * Rnd())) & CStr(Int(9 * Rnd())) & CStr(Int(9 * Rnd())) & CStr(Int(9 * Rnd()))
message.Text = "请输入正确的验证信息"
yanzheng = ""
else
message2.Text = CStr(Int(9 * Rnd())) & CStr(Int(9 * Rnd())) & CStr(Int(9 * Rnd())) & CStr(Int(9 * Rnd()))
message.text="请输入完整的信息"
end if
end sub
sub zhuce(sender as object, e as eventargs)
response.redirect("resister.aspx")
end sub
function checkuser(byval n as string, byval p as string) as string
dim strcon as string
strcon="provider=microsoft.jet.oledb.4.0;data source=" & server.mappath("..\etest.mdb")
dim conn as new oledbconnection(strcon)
dim strsql as string ="select * from 成绩表 where [学号]='"+n+"' and [密码]='"+p+"'"
conn.open()
dim cmd as new oledbcommand(strsql,conn)
dim dr as oledbdatareader=cmd.executereader()
if dr.read() then
return "ok"
else
return "c"
end if
conn.close()
end function
</script>
<html>
<body ><center><h2>用户登录</h2>
<hr>
<form id="form1" method="post" runat="server">
学 号: <asp:textbox id="txtname" size="17" runat="server"/>
<br>
密 码: <asp:textbox id="txtpass" size="19" textmode="password" runat="server"/><br>验证码: <asp:textbox id="t1" size="6" runat=server />
<asp:label id="message2" size="8" runat=server /> <br>
<asp:button id="button1" text="登录" onclick="login" runat="server"/> <asp:linkbutton text="注册" onclick="zhuce" runat="server"/><br>
<asp:label id="message" runat="server"/>
</form></center>
</body>
</html>注册的
<html>
<body><center>
<h2> 用户注册</h2>
<hr>
<form id="form1" runat="server">
姓   名:<asp:textbox id="txtname" size="17" runat="server"/><br>
密   码:<asp:textbox id="txtpass" size="19" textmode="password" runat="server"/><br>
学   号:<asp:textbox id="txtnum" size="17" runat="server"/><br><asp:button text="注册" onclick="reg" runat="server" id="button1"/><br>
<font color="red">
<asp:label id="message" runat="server"/></font>
</form></center>
</body>
</html>
<%@ import namespace="system.data.oledb"%>
<script language="vb" runat="server">
sub reg(sender as object,e as eventargs)
dim username as string=txtname.text
dim userpass as string=txtpass.text
dim usernum as string=txtnum.text
if not username="" and not userpass="" and not usernum="" then
message.text=saveuser(username,userpass,usernum)
if message.text="ok" then
session("username")=username
response.redirect("login.aspx")
end if
else
message.text="请输入完整的信息"
end if
end sub
function saveuser(byval n as string,byval p as string,byval m as string) as string
dim strcon as string="provider=microsoft.jet.oledb.4.0;data source=" & server.mappath("..\eTest.mdb")
dim conn as new oledbconnection(strcon)
dim strsql as string="insert into 成绩表([姓名],[密码],[学号]) values ('"+n+"','"+p+"','"+m+"')"
conn.open()
dim cmd as new oledbcommand(strsql,conn)
try
cmd.executenonquery()
return "ok"
catch ex as exception
return "注册出错,请联系管理员"+ex.tostring
end try
conn.close()
end function
</script>
解决方案 »
- .net环境下的在线文档
- 如果我在asp.net中产生一个控件,我要加到页面上去,我怎么控制控件的位置,这个要怎么做啊?各位高手帮忙一下
- 创建三层结构 无法引用命名空间
- 【送分了】请问下我用Datelist绑定数据,要给Datalist传值的问题。
- cookie在IE6,IE8中不好用吗?
- 框架问题求救:上下两个Frame,上面显示下来菜单,可惜显示出来的菜单变成忘上了,就是不能跨越frame
- 真的只有10分了:FormsAuthenticationTicket写入到cookie中的问题
- asp。net中的文件上传问题(新手)
- web排版的问题,有难度!
- 一个关于打开新窗口的菜鸟问题~~~在线等待~~~
- Sys.WebForms.PageRequestManagerServerErrorException: 对 COM 组件的调用返回了错误 HRESULT E_
- 百度搜索公司网站显示乱码
Exception Details: System.Data.OleDb.OleDbException: FROM 子句语法错误。