ado.net中的登录页面出现问题 [英] problem with login page in ado.net

查看:130
本文介绍了ado.net中的登录页面出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我创建了具有名称和密码字段的登录页面.当我按Enter键时,它应该显示在标签上.
但是它仅对于最近存储到数据库表中的值正常工作.此代码无法捕获已存储在表中的值.

我有这样的代码.


i created log in page with name and password fields.when i press enter it should display on a label.
but it is working correctly for the value which is stored recently to the database table only.the values which already stored in the table is not captured by this code.

i have a code like this.

string name, password, query;
        name = txtloginname.Text;
        password = txtloginpwd.Text;
        query = "select username,password,trole from userInfo";//userInfo is my table name
        SqlDataReader dr;
        SqlCommand command = new SqlCommand(query, scon);
        dr = command.ExecuteReader();
        while (dr.Read())
        {
            if (name.Equals(dr["username"].ToString()))
            {
                if (password.Equals(dr["password"].ToString()))
                {
                    string role = dr["trole"].ToString();
                    if (role.Equals("STUDENT"))
                    {
                        lblget1.Text = "welcome to" + role;
                    }
                    else
                    {
                        lblget1.Text = "welcome to" + role;
                    }
                }
                else
                {
                    lblget1.Text = "password do not match";
                }
            }
            else
            {
                lblget1.Text = "not a valid user";


}
请帮我.
谢谢.


}
plz help me.
thank you.

推荐答案

这是我见过的最糟糕的登录代码.如果你为我工作,我会解雇你.永远不要从数据库中提取正确的数据,始终让数据库检查用户是否有效.切勿将DB代码放在表示层中,而在数据层中编写.

从userInfo选择计数(*),其中username = @username AND password = @password

或选择trole(如果需要返回它),然后检查它是否为空.
This is the worst login code I have ever seen. I''d fire you if you worked for me. NEVER pull the right data out of the database, always have the DB check if the user is valid. NEVER put DB code in the presentation layer, write a data layer.

select count (*) from userInfo where username = @username AND password = @password

OR select trole if you need to return it, and check if it''s null.


这篇关于ado.net中的登录页面出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆