Wednesday, March 21, 2012

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();
}
}[/CODE]

Thanks in advanceIt was the break statement taking me out too early.sql

No comments:

Post a Comment