comparsion textvalue with database value and loginsuccessful
how to compare the text value with database value and login successfull
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Nov 21, 2013, 4:22 AM
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="Login_related_details.Login" %>
Login.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Login_related_details
{
public partial class Login : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
SqlDataAdapter sqlda;
string str;
DataTable dt;
int RowCount;
protected void btn_login_Click(object sender, EventArgs e)
{
string UserName = TextBox_user_name.Text.Trim();
string Password = TextBox_password.Text.Trim();
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "Select * from Login";
com = new SqlCommand(str);
sqlda = new SqlDataAdapter(com.CommandText, con);
dt = new DataTable();
sqlda.Fill(dt);
RowCount = dt.Rows.Count;
for (int i = 0; i < RowCount; i++)
{
UserName = dt.Rows[i]["UserName"].ToString();
Password = dt.Rows[i]["Password"].ToString();
if (UserName == TextBox_user_name.Text && Password == TextBox_password.Text)
{
Session["UserName"] = UserName;
Response.Redirect("Details.aspx");
}
else
{
lb1.Text = "Invalid User Name or Password! Please try again!";
}
}
}
}
}
HanookPosted Nov 21, 2013, 3:43 AM
Jaganathan BantheswaranPosted Nov 21, 2013, 1:28 AM
Here is an example.