Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input string was not in a correct format. - DataReader

Status
Not open for further replies.

primagic

IS-IT--Management
Jul 24, 2008
476
GB
I am trying to populate textboxes and a dropdown list on the page when loading using the following code:

Code:
Dim dtrReaderUser As SqlDataReader = SqlCommand.ExecuteReader()
        If dtrReaderUser.HasRows Then
            
            While dtrReaderUser.Read()
                Me.txtFirstname.Text = dtrReaderUser("Firstname")
                Me.txtSurname.Text = dtrReaderUser("Surname")
                Me.txtCompany.Text = dtrReaderUser("Company")
                Me.txtAddressLine1.Text = dtrReaderUser("AddressLine1")
                Me.txtAddressLine2.Text = dtrReaderUser("AddressLine2")
                Me.txtAddressLine3.Text = dtrReaderUser("AddressLine3")
                Me.txtTown.Text = dtrReaderUser("Town")
                Me.txtPostcode.Text = dtrReaderUser("Postcode")
                Me.ddlCountries.SelectedItem.Selected = dtrReaderUser("Country")
                Me.txtPhone.Text = dtrReaderUser("ContactPhone")
                Me.txtEmail.Text = dtrReaderUser("EmailAddress")

            End While

All the fields populate apart fromthe dropdown list - Me.ddlCountries.SelectedItem.Selected = dtrReaderUser("Country")

I get the error "Input string was not in a correct format."

Any ideas how I would make the selected item the value stored in the database?

 

Assuming the dropdown list has string values assigned:

Code:
Me.ddlCountries.SelectedValue = dtrReaderUser("Country").toString()


Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top