如何从sql server填充组合框中的数据

时间:2016-07-14 09:54:33

标签: vb6

我有一个组合框名称cbSection

如何在组合框中填充sql server中的数据?

任何想法都会有所帮助

-Thanks

1 个答案:

答案 0 :(得分:0)

这是直接来自VbForums(我不相信代码!),这是快速Google搜索的第一个结果。

Dim strSQL as String    'Declare the variables we need 
Dim oRS as ADODB.Recordset
  Set oRS = New ADODB.Recordset

                           'Load the data
'** change this SQL to load the data you want.
  strSQL = "SELECT Colour FROM Colours"

'** change oConn to the name of your Connection object
  oRS.Open strSQL, oConn, adOpenForwardOnly, adLockReadOnly, adCmdText
                           'Fill the combo box (or ListBox)
'** change the name of the combo to the one you want to fill
  With cboColour
    .Clear
    Do While Not oRS.EOF
'** change the name of the field here to the one you want to show
      .AddItem oRS.fields("Colour").value
      oRS.MoveNext
    Loop
  End With

                           'Tidy up
  oRS.Close
  Set oRS = Nothing