数据不显示在组合框中 [英] data not display in combo box

查看:98
本文介绍了数据不显示在组合框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

数据未显示在组合框中,但数据集中有数据


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







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

        cmbComp.DataSource = cnn.ExecuteDataset(str).Tables(0)

推荐答案

您刚刚绑定了一个数据源.在displayMember中指定列名.
请参阅以下示例

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

ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList

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



确保您的数据集不能为空



besure your dataset must not be empty


将数据源分配给组合框,然后将数据绑定到组合框
assign data source to combobox and then bind data to it


这篇关于数据不显示在组合框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆