Results 1 to 3 of 3

Thread: [RESOLVED] Grabbing first record rather than the record I am trying to find.

  1. #1

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    Resolved [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

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    Re: Grabbing first record rather than the record I am trying to find.

    Thank you so much, that was the entire problem.
    Last edited by gjon; Mar 24th, 2007 at 10:38 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width