将ComboBox绑定到MS Access数据库连接 [英] Binding ComboBox to MS Access database connection

查看:70
本文介绍了将ComboBox绑定到MS Access数据库连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我如何将ComboBox绑定到MS Access数据库内容吗?

Can anybody tell me how to bind a ComboBox to a MS Access database content?

Thanks in advance!

推荐答案

请在此处查看讨论:
Please see the discussion here: Using code to bind combo box to Access database[^].

That should help you along!

Regards,

Manfred


hi 在连接字符串中替换Access数据库文件路径,并根据需要提供表名和列名.
这是一个示例示例.
hi replace your Access database file path in the connection string and give the table name and column name as required.
this is a sample example.
Private Sub FillCombo()
       Try
           Dim fillcon As New OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=path to access file.mdb;")
           Dim asql As String = ("SELECT * FROM Items ORDER BY ItemName")
           Dim da As New OleDbDataAdapter(asql, fillcon)
           Dim ds As New DataSet
           da.Fill(ds)
           ItemNameCombo.ValueMember = "ItemName"
           ItemNameCombo.DataSource = ds.Tables(0)
           ItemNameCombo.SelectedIndex = 0
       Catch ex As Exception
           MsgBox("ERROR : " & ex.Message.ToString)
       End Try
   End Sub


好,通过使用连接字符串 [使用ADO.NET访问数据 [ ^ ]
Well, by using a Connection String[^]!

The link above provides all info about connection string. Further info regarding the data communication can be read here: Accessing data with ADO.NET[^]


这篇关于将ComboBox绑定到MS Access数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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