Hello all, Somebody please help me by modying this code.when i retrieve the Login value through stored procedure call,though i give the correct user name and password i am getting the error message "Invalid UserName or Password" means always checking the false condition only.pls help me somebody......Here is my code.
Login.cs:
public int GetLogin(string UserName, string Password)
{
SqlConnection con = new SqlConnection(str);
SqlDataAdapter da = new SqlDataAdapter("GetUserLogin", con);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.Add("@UserName", SqlDbType.VarChar, 50).Value = UserName;
da.SelectCommand.Parameters.Add("@Password", SqlDbType.VarChar, 50).Value = Password;
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
if ((ds.Tables[0].Rows[0].ItemArray[1].ToString() == UserName) && (ds.Tables[0].Rows[0].ItemArray[2].ToString() == Password))
{
return 1;
}
else
{
return 0;
}
}
else
{
return -1;
}
}
Stored Procedure:
CREATE PROCEDURE GetUserLogin( @UserName varchar(50),@Password varchar(50))
AS
select UserName, Password
From Login where UserName=@UserName and Password=@Password
RETURN
Login.aspx.cs:
protected void BtnLogin_Click(object sender, EventArgs e)
{
Session["UserName"] = TxtUserName.Text;
Login lg = new Login();
if ((lg.GetLogin(TxtUserName.Text, TxtPassword.Text) == 1)&&(DropDownList1.SelectedIndex == 1))
{
Response.Redirect("c1.aspx");
}
else if ((lg.GetAdminLogin(TxtUserName.Text, TxtPassword.Text) == 1) && (DropDownList1.SelectedValue == 0))
{
Response.Redirect("Admin.aspx");
}
else
{
Lbl1.Text = "<b>Sorry,Invalid UserName or Password</b>";
}
}
Above highlighted condition always going to else condition though i give the correct input.