如何从msaccess中填充VB.NET中的组合框 [英] How to fill combobox in VB.NET from msaccess

查看:89
本文介绍了如何从msaccess中填充VB.NET中的组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法理解为什么它不给我出局。在描述的表格中有数据,甚至数据集也已填充,我在调试器模式下看到了这一点。但是,值成员和显示成员未填充。我无法理解为什么。



我的尝试:



I cannot understand why its not giving me the out put. There is data in the described table and even the dataset is getting populated I saw that in debugger mode. But, the value member and display member are not getting populated. I cannot understand why.

What I have tried:

Private Sub frmItemEntry_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim strSql As String
        strSql = "Select UID, UnitName from UnitofMeasurement"
        Try
            conn.Open()
            With com
                .CommandType = CommandType.Text
                .CommandText = strSql
                .Connection = conn
            End With
            adp.SelectCommand = com
            adp.Fill(ds)
            adp.Dispose()
            com.Dispose()
            conn.Close()
            With cmbUnitOfMeasure
                .DataSource = ds.Tables("UnitofMeasurement")
                .ValueMember = "UID"
                .DisplayMember = "UnitName"
            End With
            
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        conn.Close()
    End Sub

推荐答案

对于 ComboBox DataTable 用作 DataSource c $ c>,请参阅 ComboBox.DataSource属性(System.Windows.Forms) [ ^ ]。



Karthik向我展示了我的方式错误。 :(
You cannot use a DataTable as the DataSource for a ComboBox, see ComboBox.DataSource Property (System.Windows.Forms)[^].

Karthik showed me the error of my way(s). :(


试试这个

try this
cmbUnitOfMeasure.ValueMember = "UID"
cmbUnitOfMeasure.DisplayMember = "UnitName"
cmbUnitOfMeasure.DataSource = ds.Tables(0)


这篇关于如何从msaccess中填充VB.NET中的组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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