Hi,
There is a logic issue in your code.
First say, your admin table contains following records
sno aID aPW
1 ID1 PW1
2 ID2 PW2
3 ID3 PW3
As per your code logic, if i give ID2 and PW2, the WHILE loop will check the database and fetches the first record ID1 and PW1 and it fails the IF condition and goes to ELSE part and closses connection and redirects to the Web page in ELSE part.
Here modified your code, see below,
protected void Page_Load(object sender, EventArgs e)
{
string a = Request.Form["uname"].ToString();
string b = Request.Form["pwd"].ToString();
OleDbConnection con = new OleDbConnection();
con.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=H:\MoratuwaLawyersAssociation\MLADB.mdb";
con.Open();
string sql = "SELECT * FROM admin";
OleDbCommand comm = new OleDbCommand(sql, con);
OleDbDataReader or;
or = comm.ExecuteReader();
bool isFound = false;
while (or.Read())
{
if ((a == or["aID"].ToString()) && (b == or["apw"].ToString()))
{
isFound = true;
break;
}
else
{
isFound = false;
}
}
con.close();
if(isFound)
{
Response.Redirect("LawyersHome.aspx");
}
else
{
Response.Redirect("IncorrectLogin.aspx");
}
}
NOTE: You are using Openconnection method. It takes time to load your data. Try using Closed connection method. That will speed up your process.
Regards,
Suresh