0

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

Edited by happygeek: fixed formatting

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by hramos
0

I am new to to ASP.net to. But something where I think you might have a problem is when you retrieve the user name and password using dr.GetString(0) and dr.GetString(1). I think it would be safer to do something like dr["username"].toString() and dr["password"].toSTring() . This assuming your columns names are username and password respectively.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.