Click here to Skip to main content
15,867,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
data not display in combo box but there is data in dataset


Public Function ExecuteDataset(ByVal commandtext As String) As DataSet
        Try

            con.Open()
            cmd.CommandType = CommandType.Text
            'cmd.CommandType = CommandType.StoredProcedure;
            cmd = New OdbcCommand(commandtext, con)
            da = New OdbcDataAdapter()
            da.SelectCommand = DirectCast(cmd, OdbcCommand)
            ds = New DataSet()
            da.Fill(ds)

            con.Close()
        Catch ex As Exception
            error1 = ex.ToString()
        Finally
            con.Close()
        End Try
        Return ds
    End Function



VB
Dim str As String
        str = "select companyname from company"
        Dim cnn As New MyConnection()

        cmbComp.DataSource = cnn.ExecuteDataset(str).Tables(0)
Posted
Updated 16-Sep-11 23:52pm
v4

You have just bind a datasource. specify column name in displayMember.
see the following example

VB
ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList

   With ComboBox1
       .DataSource = objDataset.Tables(0);
       .DisplayMember = "Description"
       .SelectedIndex = 0
   End With


besure your dataset must not be empty
 
Share this answer
 
v2
assign data source to combobox and then bind data to it
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900