Getting error assigning a DataTable to a ComboBox DataSource?

I'm trying to bind a DataTable to a ComboBox and I'm getting the error below (see screenshot). Also, I posted my code below but I remember once that I was unable to programmatically assign a DataMember/ValueMember to a ComboBox. Maybe I was doing something wrong. Here is my code below.

        Private Sub GetMerchants(ByVal iAcctID As Integer)
        Dim dt As New DataTable

            dt = BL.GetMerchants(iAcctID)
            cmbMerchants.DataSource = Nothing
            cmbMerchants.DataSource = dt(0)
            cmbMerchants.DisplayMember = "name"
            cmbMerchants.ValueMember = "merchantID"
            cmbMerchants.SelectedIndex = -1

        Catch ex As Exception
            gstrErr = "frmTransactions/GetMerchants() - " & ex.Message
            MessageBox.Show(gstrErr, "User Notification", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub
Who is Participating?
ElrondCTConnect With a Mentor Commented:
dt(0) is a single row of a DataTable. You need to assign the entire DataTable to be the DataSource:

cmbMerchants.DataSource = dt
I don't want to sound ungrateful, but why did you think my response deserved only a B grade? How was it less than what you needed? It's customary, when you think there's a shortcoming in an answer, to explain what the problem is. This can be an opportunity for me to learn as well as you. Thanks.
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

BlakeMcKennaAuthor Commented:

To be honest I'm not quite sure how this point system/grade thing works with EE. I normally give an "Excellent" when someone provides a solution that works. As for your answer of

    cmbMerchants.DataSource = dt

I have already tried this and still get the same results. I'm getting the error when I try to assign the DataMember/ValueMember properties...assigning the DataSource wasn't the issue.
So are you saying that the problem isn't solved? Then why did you close the question?

The DataTable is getting loaded, and gets its structure, from BL.GetMerchants(iAcctID). Have you checked to make sure the column names "name" and "merchantID" are in the table? What's the exact error you get, and what line is active when you get it?
BlakeMcKennaAuthor Commented:
I actually figured it out after you had made your last post...which is why I closed it. This is an application that I am working on for myself and it's on my machine at home so I can't recall what the fix was. My apologies for any confusion.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.