日期:2014-05-17  浏览次数:20391 次

判断用户名错误还是密码错误怎么会报错的呢
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Collections;

public partial class login : System.Web.UI.Page
{
 
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        //连接数据库
        SqlConnection sqlconstr = new SqlConnection();
        sqlconstr.ConnectionString = "server=localhost;database=employee;uid=sa;pwd='111111'";
        sqlconstr.Open();

        //Response.Write(sqlconstr.State.ToString());
        
        //获取客户端的信息
        string strUsername = this.Username.Text.Trim();
        string strPassword = this.Password.Text.Trim();

        //创建SQL语句
        string mysql = "select * from empInfo where username='" + strUsername+ "' and password='" + strPassword + "'";

        SqlCommand cmd = new SqlCommand(mysql, sqlconstr);

        SqlDataReader dr = cmd.ExecuteReader();
        if (dr.Read())
        {
            //Response.Write("登录成功");
            //Response.Write("<script>alert('登录成功');location='emplist'</script>");
           // Response.Redirect("emplist.aspx");
            string power=dr["per"].ToString();
            if (this.userRadio.Checked == true && power == "2")
            {
                Response.Redirect("emplist.aspx");
            }
            else
            {
                if (this.admRadio.Checked == true && power == "1")
                {
                    Response.Redirect("admManage.aspx");
                }
                else