主题:combo1不能显示SQL数据
xiang1434
[专家分:0] 发布于 2008-09-27 15:36:00
Private Sub Form_Load()
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=koubai;Data Source=192.168.101.19"
cn.Open
rs.ActiveConnection = cn
rs.Open "select 模具名 from master", cn, 1, 3
Combo1.Clear
For i = 0 To rs.RecordCount - 1
Combo1.AddItem rs(0) & ""
rs.MoveNext
Combo1.ListIndex = 0
Next i
rs.Close
End Sub
回复列表 (共2个回复)
沙发
老大徒伤悲 [专家分:29120] 发布于 2008-09-28 16:13:00
For i = 0 To rs.RecordCount - 1
Combo1.AddItem rs(0) & ""
rs.MoveNext
Combo1.ListIndex = 0
Next i
你把这几行想做的事情讲讲看
板凳
oO羽姿Oo [专家分:600] 发布于 2008-09-29 09:41:00
获得数据集RS后.用以下代码:
While Not (rs.EOF = True Or rs.BOF = True) '当数据集有数据并且不是记录尾时
x = rs.Fields("CardStyleName") 'dim x as string 获得数据
DoEvents '防止数据过多时加载数据出现程序无响应
Me.Combo1.AddItem x '加入一条记录
rs.MoveNext '移到下一记录
Wend
Me.Combo1.Text = Me.Combo1.List(0) '置默认显示第一条记录
我来回复