首页 > 编程 > .NET > 正文

ASP.NET一个最简单的会员登陆代码

2024-07-10 13:10:45
字体:
来源:转载
供稿:网友

商业源码热门下载www.html.org.cn

是用来新手入门的,高手们不要见笑呀!
string conn = "server=.;database=login;user id=sa;pwd=123";
        sqlconnection cn = new sqlconnection(conn);
        cn.open();
        string strsql = "select user_name,user_pwd from admin where user_name='" + textbox1.text + "' or user_pwd='" + textbox2.text + "'";
        sqlcommand cmd = new sqlcommand(strsql, cn);
        sqldatareader rd = cmd.executereader();
        if (rd.read())
        {
            if (rd.getvalue(0).tostring() == textbox1.text)
            {
                if (rd.getvalue(1).tostring() == textbox2.text)
                {
                    response.redirect("default.aspx");
                }
                else
                {
                    response.write("<script>alert('密码错误!')</script>");
                }
            }
            else
            {
                response.write("<script>alert('用户名错误!')</script>");
            }
        }
        else
        {
            response.write("<script>alert('用户不存在!')</script>");
        }
    }

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表