在 Microsoft Visual Basic 6.0 中填充组合框 [英] Populate combobox in Microsoft Visual Basic 6.0
问题描述
我在 Microsoft Visual Basic 6.0 中有一个组合框.我必须将项目添加到组合框中.这些项目存储在 SQL 数据库中 Column1 的一个表中.我不确定如何让这些项目在运行时显示在组合框中,以便用户可以选择不同的选项.
I have a combo box in Microsoft Visual Basic 6.0. I have to add items to the combo box. These items are stored in SQL database within a table in Column1. I am not sure how to get those items to display in combobox on run time so the user can select different options.
注意:表格只有一列.
这是我目前编写的代码:
Here is the code I have written so far:
'Public Function GetProvincialRidingRst() As ADODB.Recordset
'
' Dim rst As ADODB.Recordset
' Dim strSQL As String
'
' strSQL = "Select * from ProvincialRidings"
'
' Set rst = New ADODB.Recordset
' rst.ActiveConnection = cn
' rst.Open strSQL, , adOpenKeyset, adLockBatchOptimistic
'
' Set GetProvincialRidingsRst = rst
'
'End Function
我不知道如何从这里处理.
I am not sure how to process from here.
推荐答案
一旦您有了记录集,只需循环遍历这些记录并将它们添加到 ComboBox 即可.应该这样做:
Once you have a recordset it's just matter of looping through the records and adding them to the ComboBox. Something like this ought to do it:
Combo1.Clear
With myRS
Do While Not .EOF
Combo1.AddItem ![myColumn]
.MoveNext
Loop
.Close
End With
显然,您需要将 myColumn
替换为表中的实际列名称.
Obviously, you'll need to replace myColumn
with the actual column name from the table.
这篇关于在 Microsoft Visual Basic 6.0 中填充组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!