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

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.

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.