Listbox Databinding problem

I'm using the following code to bind a dataset to a listbox on my form. 

 'Get Data and display in combobox

        Dim cmdString As String = "Select * from LOV_facility"
        Dim connString As String = "yadda, yadda, yadda"
        Dim myConnection As SqlConnection = New SqlConnection(connString)

        Try
            ' Open connection
            myConnection.Open()
            Dim da As SqlDataAdapter = New SqlDataAdapter(cmdString, myConnection)
            Dim dataSet1 As DataSet = New DataSet
            da.Fill(dataSet1, "LOV_Facility")
            cbGetFac.DataSource = dataSet1
            cbGetFac.DisplayMember = "Fac_Name"

        Catch ae As SqlException
            MessageBox.Show(ae.Message)
        End Try

The only thing that I get in the drop-down list is:System.Data.DataViewManagerListItemTypeDescriptor

     Can anyone see what I've done wrong. I'm new to ADO.net and this is making my head hurt :>). Thanks in advance.

Mark F.


Answer this question

Listbox Databinding problem

  • Mr. Paoli

    Problem solved. I had an incorrect entry in object properties window.
  • ghostface039

    Hello Mark

    I went though your code and found a small problem which lies in the following line:

    cbGetFac.DataSource = dataSet1

    Here you should use the following line instead:

    cbGetFac.DataSource = dataSet1.Tables(0)

    I hope that this works for you.

    Aditya



  • Listbox Databinding problem