Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8610533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:09:17+00:00 2026-06-12T04:09:17+00:00

I trust you’re all well. I would like to know what I’m doing wrong

  • 0

I trust you’re all well. I would like to know what I’m doing wrong and how to fix it. My intent with the code below is the query my MySQL database and display one column of the table inside a ComboBox. Then, when that value in the ComboBox is selected, I want all the records associated to be populated into other controls on my form (I’ll create a separate question for this part).

Right now, the query is working but the ComboBox isn’t being populated. What am I doing wrong? Please help, thanks.

HERE’S MY CODE:

    Private Sub RetrieveMySQLdata()

    Try
        Dim dbConn As New MySqlConnection
        Dim dbQuery As String = ""
        Dim dbCmd As New MySqlCommand
        Dim dbAdapter As New MySqlDataAdapter
        Dim dbTable As New DataTable
        If dbConn.State = ConnectionState.Closed Then
            dbConn.ConnectionString = String.Format("Server={0};Port={1};Uid={2};Password={3};Database=accounting", FormLogin.ComboBoxServerIP.SelectedItem, My.Settings.DB_Port, My.Settings.DB_UserID, My.Settings.DB_Password)
            dbConn.Open()
        End If

        dbQuery = "SELECT *" & _
                   "FROM cc_master INNER JOIN customer ON customer.accountNumber = cc_master.customer_accountNumber " & _
                   "WHERE customer.accountNumber = '" & TextBoxAccount.Text & "'"
        With dbCmd
            .CommandText = dbQuery
            .Connection = dbConn
        End With
        With dbAdapter
            .SelectCommand = dbCmd
            .Fill(dbtable)
        End With
        Dim i As Integer
        For i = 0 To dbTable.Rows.Count - 1
            ComboBoxCard.ValueMember = "ccNumber"

        Next
    Catch ex As Exception
        MessageBox.Show("A DATABASE ERROR HAS OCCURED" & vbCrLf & vbCrLf & ex.Message & vbCrLf & _
                    vbCrLf + "Please report this to the IT/Systems Helpdesk at Ext 131.")
    End Try

End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:09:19+00:00Added an answer on June 12, 2026 at 4:09 am

    Where are you trying to populate the ComboBox? The only interaction I see is here:

    For i = 0 To dbTable.Rows.Count - 1
        ComboBoxCard.ValueMember = "ccNumber"
    Next
    

    Which I’m guessing isn’t doing what you think it’s doing. For one thing, you’re setting ValueMember to the same value multiple times in a loop. Nothing in the statement changes with each iteration of the loop, so why loop it?

    More specifically, ValueMember isn’t actually any kind of displayed value. It’s used to indicate which field in the bound data should contain the value. This is used when you provide a DataSource for the control, which you’re missing.

    I’ll assume the DataSource should be dbTable, so you’re probably looking to do something like this:

    ComboBoxCard.DataSource = dbTable
    ComboBoxCard.ValueMember = "ccNumber"
    ComboBoxCard.DisplayMember = "Some Other Field in the database"
    

    I don’t remember if you need to explicitly call .DataBind() on the control after these statements, but the example I linked to doesn’t do it so I’ll leave it out.

    Essentially what you’re trying to do in your code is loop through the results and add them to the ComboBox. You don’t need to do this. The ComboBox is capable of doing this internally if you just point its DataSource to the set of data being used and tell it which fields it needs to use on that set. This is called data binding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently our Web hosting provider moved to a medium trust level for all shared
I know that Entity Framework supports Partial trust, I personally blogged about that It
I know to never trust user input, since undesirable input could be compromise the
Does anyone know of an algorithm for computing how much you 'trust' another user
I am trying to use the code from the 'Certificate,Key and trust programming guide'.
Can I really and truly trust .NET to initialize fields (like ints, structs and
What are the things that Medium Trust stops you from doing? For example, I've
I wonder why Java compiler doesn't trust in this line of code : List<Car>
I want to ensure that Internet Explorer on all domain computers trust all domain
How to check from .net code whether Trust access to the VBA project object

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.