表里对应ID='abcd'这个账号的密码为456 你用sql :select count(*) cnt from tb where id='abcd' and 密码='666' 去查询,如果count数为0,则没有查询到记录,就提示用户账号或密码错误就可以了。 这时候程序需要退出到登陆界面,不能让程序继续往下执行了。
declare @table table (id varchar(4),密码 int) insert into @table select 'abcd',456 union all select 'xxxx',666select * from @table /* id 密码 ---- ----------- abcd 456 xxxx 666 */select * from @table where id='abcd' and 密码=666 /* id 密码 ---- -----------(0 row(s) affected) */ select出来的结果是满足判断条件的行,如果有2个条件 中间用and,需要某行同时满足,才能查询出来。
其实先找到ID,然后再判断对应ID的密码是否正确就可以了,
declare @table table (id varchar(4),密码int) insert into @table select 'abcd',456 union all select 'xxxx',666 if exists(select 1 from @table where id='abcd' and 密码=666) begin print '密码正确' end else begin print '密码错误' end/* 密码错误 */
select * from 一张表 where id='abcd' and 密码='666' -- 注意ID和密码中间是and就是前一字段和后一字段都符合,查询才有返回结果 select * from 一张表 where id='abcd' or 密码='666' --如果是用的or,那么随便前后哪个字段只要有一个符合,查询就有返回结果。
你用sql :select count(*) cnt from tb where id='abcd' and 密码='666'
去查询,如果count数为0,则没有查询到记录,就提示用户账号或密码错误就可以了。
这时候程序需要退出到登陆界面,不能让程序继续往下执行了。
登入界面?理论上要做成在ID框输入ID,在密码框输入密码后验证。
declare @table table (id varchar(4),密码 int)
insert into @table
select 'abcd',456 union all
select 'xxxx',666select * from @table
/*
id 密码
---- -----------
abcd 456
xxxx 666
*/select * from @table where id='abcd' and 密码=666
/*
id 密码
---- -----------(0 row(s) affected)
*/
select出来的结果是满足判断条件的行,如果有2个条件 中间用and,需要某行同时满足,才能查询出来。
declare @table table (id varchar(4),密码int)
insert into @table
select 'abcd',456 union all
select 'xxxx',666
if exists(select 1 from @table where id='abcd' and 密码=666)
begin
print '密码正确'
end
else
begin
print '密码错误'
end/*
密码错误
*/
abcd 456
xxxx 666你的ID在输入的时候就要验证,不能有重复值id 密码
abcd 456
xxxx 666
abcd 666如果这样就会返回两条记录csdn 的帐号有一个ID,还有一个登录名,还有密码,不知道csdn加一个ID干嘛?
如下:
密码_输入 是不是等于 (select 密码 from tb where id=id_输入)
select * from 一张表 where id='abcd' and 密码='666'
查询到的结果是什么也没有c#登录的,新手互相学习//前面初始化数据库连接...
string sqlstr="select * from 一张表 where id='" + textBox1.Text.Trim() + "' and 密码='" + textBox1.Text.Trim() + "'"; //文本框1里面输入id,2里面输入密码。
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
try
{
da.fill(ds);
}
catch
{
}
if (ds.Tables[0].Rows.Count == 0) //在DS里面检查你的SQL查询语句是否有返回行数,如果为0则不让你登录。
{
MessageBox.Show("请检查您的用户名和密码!", "提示");}
else
{
this.DialogResult = DialogResult.OK;//返回为真,可以由登录界面跳转到指定界面。
}
例如上面的用户输入abcd但是密码输入666显然是第二列属于xxxx的。但也是在密码列里的,SQL会不会查询到666认为结果是真的
select * from 一张表 where id='abcd' and 密码='666'
-- 注意ID和密码中间是and就是前一字段和后一字段都符合,查询才有返回结果
select * from 一张表 where id='abcd' or 密码='666'
--如果是用的or,那么随便前后哪个字段只要有一个符合,查询就有返回结果。