Click here to Skip to main content
15,891,711 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I am having a login page where I need to enter the login name and password for a user, which I need to verify with the backend database, using LINQ.

I have tried but I am not getting.

Can anybody assist.

Following is the underlying code.

C#
protected void Button1_Click(object sender, EventArgs e)
    {
        QuizUserDetailsDataContext context = new QuizUserDetailsDataContext(ConfigurationManager.ConnectionStrings["krs_projectConnectionString"].ToString());
        krs_userinfo k = new krs_userinfo();
        //if(TextBox1.Text.Equals(k.uname.ToString()))
        if(TextBox1.Text.Equals(k.uname) && (TextBox2.Text.Equals(k.password)))


            Response.Redirect("~/Quizaspx.aspx");




    }


This is not working, but not giving any error also.

Many Thanks in Advance.
Posted

1 solution

You have declared an object as follows:

krs_userinfo k = new krs_userinfo();


But, as you haven't retrieved this object from the database, this is a blank object. So, the next if statement always evaluates to false.

if(TextBox1.Text.Equals(k.uname) && (TextBox2.Text.Equals(k.password)))


What you might need is something like as follows:

//Retrieve the user from the database by the username and password
krs_userinfo k = GetUserFromDBByUserNameAndPassword(TextBox2.Text,TextBox2.Text);

if(k != null)
{
    //User retrieved from database. So, userName and password is correct
    Response.Redirect("~/Quizaspx.aspx");
}


So, you just need to implement the method GetUserFromDBByUserNameAndPassword(userName,password) which will query the database to retrieve the user object with the supplied userName and password.
 
Share this answer
 
Comments
mohangbits 14-Sep-10 4:49am    
is it working?
Al-Farooque Shubho 14-Sep-10 5:09am    
It will surely work, if you can implement the method that queries the database to retrieve the user. See the statement in my answer:

"
So, you just need to implement the method GetUserFromDBByUserNameAndPassword(userName,password) which will query the database to retrieve the user object with the supplied userName and password."
Mukund Kallapur 14-Sep-10 14:15pm    
Hello Al-Farooque Shubho,

Thank you very much for your answer, but I am little bit stuck in the implementation of the GetUserFromDBByUserNameAndPassword method, Could you kindly provide the snippet, if possible.

Kindly assist

Many Thanks in Advance

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900