且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将ComboBox绑定到MS Access数据库连接

更新时间:2021-12-11 02:09:04

请在此处查看讨论: ^ ].

那应该对你有帮助!

问候,

曼弗雷德(Manfred)
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[^]