回 帖 发 新 帖 刷新版面

主题:数据库问题

例如有一张表,有两个属性:一个是ID,一个是passWord.
请问怎样通过代码实现,当用户输入ID时,返回到数据库,判断该ID是否存在,如存在,再判断密码是否正确~谢谢了![em1]

回复列表 (共4个回复)

沙发

对了,是用c#实现!

板凳

在存储结构里面写:
if exists(select userID from table where userID=@userID)
begin
if exists(select password from table where password=@password)
begin
return 0
end
else return -1
end
else return -2
0成功-1 密码错-2用户错

3 楼

以上为部分代码?

4 楼

使用嵌套查询就可以了。还可以先查询ID,确认存在该ID后再查询该ID以及密码。
select * from 表名 where 密码='输入的密码' and ID in(select * from 表名 where ID='输入的ID' )

select count(*) from 表名 where ID='输入的ID'
取count(*)的值,如果大于0,再执行select * from 表名 where 密码='输入的密码' and ID='输入的ID'

我来回复

您尚未登录,请登录后再回复。点此登录或注册