信阳师范学院升格大学:ASP判断的一个问题,高手进来

来源:百度文库 编辑:高考问答 时间:2024/03/29 23:23:25
ASP编程。一个提交学生名和学号的页面,如何实现学号唯一不重复呢?给个例子哦

首先
Set Rs=Server.CreateObject(\"Adodb.RecordSet\")
sql=\"select 学号 from 表 where 学号=\'\"你要添加的学号\"\'\"
Rs.open Sql,conn,3,2
if (Rs.eof or Rs.bof) then
可以添加
Else
学号已经存在
end if

sql="select * from [学生表] where 学号='"&id&"'"
set rs=conn.execute(sql)
if rs.eof then
response.write("该学号不存在")
else
response.write("该学号已经存在")
end if

简单的写.

你输入的学号假如是存放在变量 a 中
数据库 mdb 列 stu(学生) num(学号)
select * from mdb where num=a

if rs.eof=true then
response.write("学号有重复数据!")
end if

只是简单的思路.看你完应该明白.

if exists(select * from 表 where 学号字段名=要插入的学号) then
response.write("<script>alert('已存在该学号');history.go(-1);</script>")
else
insert into 表(学号,学生名) values(要插入的学号,"要插入的学生名")
response.write("<script>alert('插入成功');</script>")
end if