[RESOLVED] Grabbing first record rather than the record I am trying to find.
I tried checking to see if the point at which the reader was, that if it was the record I am looking for to go ahead and add the table data to a label. But for some reason it's only taking the first record in the database and not the one I thought I was at.
Code:
public void UpdateMaleHistLbl()
{
SqlConnection conn = new SqlConnection("Server=localhost\\SqlExpress;Database=MyFamTree;" + "Integrated Security=True");
SqlCommand comm = new SqlCommand("SELECT * FROM FatherHistTable, MotherHistTable, UsersTable WHERE UsersTable.UserName = @usrnmeLbl ", conn);
comm.Parameters.AddWithValue("@usrnmeLbl", usrnmeLbl.Text);
conn.Open();
SqlDataReader reader = comm.ExecuteReader();
while (reader.Read())
{
string usr = reader["username"].ToString();
usr = usr.TrimEnd();
string pss = reader["password"].ToString();
pss = pss.TrimEnd();
if (usrnmeLbl.Text == usr)
{
if (hiddenpassLbl.Text == pss)
{
maleHistLbl.Text = reader["GG_Grandfather"] + " > ";
maleHistLbl.Text += reader["G_Grandfather"] + " > ";
maleHistLbl.Text += reader["Grandfather"] + " > ";
maleHistLbl.Text += reader["Father"] + " > ";
maleHistLbl.Text += reader["Son"] + " > ";
maleHistLbl.Text += reader["Grandson"] + " > ";
maleHistLbl.Text += reader["G_Grandson"] + " > ";
maleHistLbl.Text += reader["GG_Grandson"] + "<br /><br />";
}
}
break; //exit out of the loop since user found
}
reader.Close();
conn.Close();
}
}
Thanks in advance
Re: Grabbing first record rather than the record I am trying to find.
your break; is outside of your if check....might want to move it up a couple of lines to inside the check of the password.
-tg
Re: Grabbing first record rather than the record I am trying to find.
Thank you so much, that was the entire problem.