dadonofmem 0 Newbie Poster

I have a strange issue going on here. I have a button named btnLookUp that when clicked performs a search in a SQL database using an ID that is input into a textbox named txtIdNbr. I have data in all rows of the database and have verified it more than once. While reading data and putting the data into the appropriate textboxes and setting the text on drop down lists it just stops executing the code. I have put in breakpoints in and around the lines I have commented below to see what was happening and those three lines its like they just aren't even there. BUT if you click the button again without changing the number in txtIdNbr, it executes ALL the lines of code and the three that didn't work the first time you cicked it, worked the second time. So, I thought I'd just put another button on the page named btnLookUp2 and set it to hidden and then call it right before the End Sub it does the same thing: one click everything but the three lines work. Click it again and everything works. This happens in Google Chrome, Internet Explorer 9, and Firefox 10 so it's not browser specific. Here is the code I am using. I have added comments to the lines that are not doing as expected the first time. xConnStr is publicly declared and I have imported System.Data.SqlClient. Any ideas??

Protected Sub btnLookUp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLookUp.Click
        ' Make sure the user entered an ID number.
        If txtIdNbr.Text.Trim.ToString = "" Then Exit Sub

        ' Declare variables.
        Dim strSQL As String = "SELECT * FROM Table1 WHERE strId LIKE '" & txtIdNbr.Text.Trim.ToString & "'"
        Dim xConn As SqlConnection = Nothing, xCmd As SqlCommand, xDR As SqlDataReader

        ' Try to connect to the database and see if there is a record of the ID number entered.
        ' If no record is found a message will be displayed to the user.
        Try
            ' Create the connection to the SQL database and open the connection.
            xConn = New SqlConnection(xConnStr)
            xConn.Open()

            ' Create a SQL command and execute it in a SQL DataReader.
            xCmd = New SqlCommand(strSQL, xConn)
            xDR = xCmd.ExecuteReader()

            ' Check to make sure the ID number was found.
            If xDR.HasRows = False Then
                ' Alert the user that the ID number was not found.
                pnlError.Visible = True ' Show the error panel.
                pnlDetails.Visible = False ' Hide the Details panel.
                lblError.Text = "ID  " & txtIdNbr.Text.ToString & " was not found. Please double check the ID number entered."
            End If

            ' Read the DataReader and put all the information into the appropriate controls.
            While xDR.Read()
                ' Insert the information into the appropriate fields for editing.
                pnlDetails.Visible = True ' Show my details panel.
                pnlError.Visible = False ' Hide the error panel.
                txtDescription.Text = xDR("strDescription").ToString
                txtExt.Text = xDR("strExt").ToString
                txtInt.Text = xDR("strInt").ToString
                txtAddr1.Text = xDR("strAddr1").ToString
                txtAddr2.Text = xDR("strAddr2").ToString
                txtCity.Text = xDR("strCity").ToString
                txtState.Text = xDR("strState").ToString
                txtZip.Text = xDR("strZip").ToString
                txtPhone.Text = xDR("strPhone").ToString
                txtfName.Text = xDR("strFname").ToString
                txtLname.Text = xDR("strLname").ToString
                ddlPhoneType.Text = xDR("strPhoneType").ToString
                ddlMonth.Text = xDR("strMonth").ToString
                ddlDay.Text = Left(xDR("strDay").ToString, 7)
                ddlYear.Text = xDR("strYear").ToString
                ddlSex.Text = xDR("strSex").ToString          ' DOES NOT WORK RIGHT THE FIRST TIME!
                ddlRace.Text = xDR("strRace").ToString        ' DOES NOT WORK RIGHT THE FIRST TIME!
                ddlSocial.Text = xDR("strSocial").ToString    ' DOES NOT WORK RIGHT THE FIRST TIME!
            End While

            ' Close the connection.
            xConn.Close()
        Catch ex As Exception
             ' Show the error panel and hide the details panel.
             pnlError.Visible = True
             pnlDetails.Visible = False
            
             ' Show the error in the error label.
             lblError.Text = ex.ToString
        End Try
    End Sub