Hi friends,
I am learning ASP.NET.
I have designed a login form with username and password.The code i have given in Button click event is:
SqlConnection con;
SqlDataReader dr;
int t;
con = new SqlConnection("Persist Security Info=False;Uid=sa;Password=q1w2e3/;Initial Catalog=YOGADATA;Data Source=PC-1");
con.Open();
SqlCommand com = new SqlCommand("select * from Login", con);
t = 0;
dr = com.ExecuteReader();
dr.Read();
try
{
do
{
if(TextBox1.Text.Equals((dr.GetString(0)).ToString()) && TextBox2.Text.Equals((dr.GetString(1)).ToString()))
{
t = 1;
}
}while(dr.Read());
}
catch
{
}
finally {
con.Close();
dr.Close();
}
if (t == 1)
{
Lblmsg.Visible = true;
Lblmsg.Text = "You are Logged in successfully";
LinkButton1.Visible = true;
}
else
{
Lblmsg.Visible = true;
Lblmsg.Text = "Login Failed,Try again";
}
In my data table login i have created two fields username and password and entered some data.
Now my problem is it is not giving any error.But for currect user name and password also it is displaying that login failed.
please help me to solve my problem