DAL层代码:
public  Users SelectUserByUserNameAndPassWordAndPowerId(string userName, string passWord,string powerId) 
        {
            Users users = null;
            string sql = "select * from Users where UserName=" + "'" + userName + "' and PassWord=" + "'" + passWord + "'and " + "'"+powerId+"'";
            using (SqlDataReader reader = DBHelper.ExcuteReader(sql))
            {
                if (reader.Read()) 
                {
                    users = new Users();
                    users.Id = Convert.ToInt32(reader["Id"]);
                    users.UserName = reader["UserName"].ToString();
                    users.Password = reader["PassWord"].ToString();
                    users.PowerId = Convert.ToInt32(reader["PowerId"]);
                    users.Lastlogip = reader["LastLogIp"].ToString();
                    users.Logtime = Convert.ToDateTime(reader["LogTime"]);
                    users.Isloged = Convert.ToInt32(reader["IsLoged"]);
                }
                return users;
            }
        }
BLL层:
 public static bool Login(string UserName,string PassWord,string PowerId) 
        {
            UsersDAL usersdal = new UsersDAL();
            Users user = null;
            user = usersdal.SelectUserByUserNameAndPassWordAndPowerId(UserName, PassWord, PowerId);
            if (user==null)
            {
                return false;
            }
            else 
            {
                return true ;
            }
        }
WEB层:
 <tr >
       <td width="100" height="40">账&nbsp;号</td>
       <td height="40">
        <div align="left">
        <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="不能为空!" ControlToValidate="txtUserName"></asp:RequiredFieldValidator>
        </div>
       </td>
      </tr>
      <tr>
       <td width="100" height="40">密&nbsp;码</td>
       <td height="40">
        <div align="left">
         <asp:TextBox ID="txtUserPwd" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="不能为空!" ControlToValidate="txtUserPwd"></asp:RequiredFieldValidator>
        </div>
       </td>
      </tr>
      <tr>
       <td align="center" colspan="3">
           <asp:DropDownList ID="RoleDropDownList" runat="server">
              <asp:ListItem Value="|1|">学工处</asp:ListItem>
              <asp:ListItem Value="|2|">宿舍楼管</asp:ListItem>
              <asp:ListItem Value="|3|">维修人员</asp:ListItem>              
           </asp:DropDownList>
       </td>
      </tr>
      <tr>
       <td align="left" colspan="3" >
           <a href="StuLogin.aspx" style="text-decoration:none;" >学生请点击此处</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
           <asp:Button ID="txtButton" runat="server" Text="登录" OnClick="txtButton_Click"/>
       </td>
      </tr>
      <tr>
       <td align="center" colspan="3" >
           <asp:Label ID="lblmessage" runat="server" forecolor="Red"></asp:Label>
       </td>
      </tr>
对应的CS代码: protected void RoleDropDownList_SelectedIndexChanged()
        {
            if (RoleDropDownList.SelectedIndex == 1) 
            {
                Response.Redirect("Admin/Default.aspx");
            }
            if (RoleDropDownList.SelectedIndex == 2)
            {
                Response.Redirect("Department/Default.aspx");
            }
            if (RoleDropDownList.SelectedIndex == 3)
            {
                Response.Redirect("Maintain/Default.aspx");
            }
        }
        protected void txtButton_Click(object sender, EventArgs e) 
        {
            string UserName = txtUserName.Text.Trim();
            string PassWord = txtUserPwd.Text.Trim();
            string PowerId = RoleDropDownList.Text.Trim();
            bool success = UsersBLL.Login(UserName, PassWord,PowerId);
            if (success)
            {
                RoleDropDownList_SelectedIndexChanged();
            }
            else 
            {
                lblmessage.Text = "用户名或密码出错!";
            }
        }

解决方案 »

  1.   

    string sql = "select * from Users where UserName=" + "'" + userName + "' and PassWord=" + "'" + passWord + "'and " + "'"+powerId+"'";最后一个and后 缺 = xxx
      

  2.   

    public Users SelectUserByUserNameAndPassWordAndPowerId(string userName, string passWord,string powerId)  
      {
      Users users = null;
      string sql = "select * from Users where UserName=" + "'" + userName + "' and PassWord=" + "'" + passWord + "'and " + "'"+powerId+"'";----------------------------
    是要根据userName,passWord,powerId来查询么? string sql = "select * from Users where UserName='" + userName + "' and PassWord='" + passWord + "'and powerId='" + powerId+"'";
      

  3.   

    string sql = "select * from Users where UserName='" + userName + "' and PassWord='" + passWord + "' and "+powerId+"";
    检查powerId值
    在查询分析器执行
      

  4.   

    一个是楼上说的问题 还有个是 RoleDropDownList的取值问题
      

  5.   

    请问5楼,我把那个SQL语句改了之后,还把那个roledropdownlist下面的value改了,但是现在在那个登陆页面就是登不进去了,去掉了那竖,我估计是CS文件有问题了,5楼楼主帮我改改,让我能登进去,谢谢!
      

  6.   


    public Users SelectUserByUserNameAndPassWordAndPowerId(string userName, string passWord,string powerId)  
      {
      Users users = null;
      string sql = "select * from Users where UserName=" + "'" + userName + "' and PassWord=" + "'" + passWord + "'and " + "'"+powerId+"'";
      using (SqlDataReader reader = DBHelper.ExcuteReader(sql))
      {
      if (reader.Read())  
      {
      users = new Users();
      users.Id = Convert.ToInt32(reader["Id"]);
      users.UserName = reader["UserName"].ToString();
      users.Password = reader["PassWord"].ToString();
      users.PowerId = Convert.ToInt32(reader["PowerId"]);
      users.Lastlogip = reader["LastLogIp"].ToString();
      users.Logtime = Convert.ToDateTime(reader["LogTime"]);
      users.Isloged = Convert.ToInt32(reader["IsLoged"]);
      }
      return users;
      }
      }
    你传值的类型错了
      

  7.   

    public Users SelectUserByUserNameAndPassWordAndPowerId(string userName, string passWord,string powerId)  
      {
      Users users = null;
      string sql = "select * from Users where UserName=" + "'" + userName + "' and PassWord=" + "'" + passWord + "'and " + "'"+powerId+"'";
      using (SqlDataReader reader = DBHelper.ExcuteReader(sql))
      {
      if (reader.Read())  
      {
      users = new Users();
      users.Id = Convert.ToInt32(reader["Id"]);
      users.UserName = reader["UserName"].ToString();
      users.Password = reader["PassWord"].ToString();
      users.PowerId = Convert.ToInt32(reader["PowerId"]);
      users.Lastlogip = reader["LastLogIp"].ToString();
      users.Logtime = Convert.ToDateTime(reader["LogTime"]);
      users.Isloged = Convert.ToInt32(reader["IsLoged"]);
      }
      return users;
      }
      }
      

  8.   

     protected void txtButton_Click(object sender, EventArgs e)  
      {
      string UserName = txtUserName.Text.Trim();
      string PassWord = txtUserPwd.Text.Trim();
      string PowerId = RoleDropDownList.Text.Trim();
      bool success = UsersBLL.Login(UserName, PassWord,PowerId);
      if (success)
      {
      RoleDropDownList_SelectedIndexChanged();
      }
      else  
      {
      lblmessage.Text = "用户名或密码出错!";
      }
      }获取的值到底是个数值 还是一个字符值
      

  9.   

    改成int型后,在CS文件里面就出问题了,你觉得应该怎样改啊,再指点下啊
      

  10.   


    既然是得到数字 string PowerId = RoleDropDownList.Text.Trim();
    获取到底却是那个值
      

  11.   

    如果 PowerId 是个外键 可以intPowerId = RoleDropDownList.SelectedIndex+1;
    这样得到数字