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.

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.

You need to write Linq to SQL query to verift login name and password against backend database. I assume krs_userinfo is kind of table where you want to verify your login name and password. What you have done is you are directly checking your textbox value with properties/field name of krs_userinfo. Instead you need to write query in below ways :

var queryKRSUI = From KRSUI in context.krs_userinfo
                 Where KRSUI.uname == textbox1.text.trim()
                 && KRSUI.password == textbox2.text.trim()
                 Select KRSUI;
if(queryKRSUI.Any())
    Response.Redirect("~/Quizaspx.aspx");    
else
    "Invalid LoginName/Password.";

Try by this and let us know...

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.