标题:combo控件与数据库
只看楼主
kaixinsiqi
Rank: 1
等 级:新手上路
帖 子:186
专家分:0
注 册:2006-11-28
 问题点数:0 回复次数:1 
combo控件与数据库
我有一个SQL数据库CMSystem,里面有一个部门表,表里的字段为ID,部门名称,我想把部门名称加到一个combo控件中,怎么做呀,我主要是不会和数据库的连接,怎样在在打开的数据里,从指定的表里将数据读出来.
搜索更多相关主题的帖子: combo 数据库 控件 
2006-12-19 11:36
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
得分:0 
Dim dbConn As ADODB.Connection
Dim Rst As ADODB.Recordset

Dim conString As String
conString = "Provider=sqloledb;Data Source=127.0.0.1;Initial Catalog =Northwind;User Id =sa;Password=coffee;"
Set dbConn = CreateObject("ADODB.Connection")

dbConn.ConnectionString = conString
dbConn.Open

Set Rst = CreateObject("ADODB.Recordset")
With Rst
.CursorLocation = adUseClient
.Open "select Distinct ShipCity from orders order by ShipCity asc", dbConn, adOpenForwardOnly, adLockReadOnly, adCmdText
End With

Dim i As Long
For i = 0 To Rst.RecordCount - 1
Combo1.AddItem Rst.Fields("ShipCity").Value
Rst.MoveNext
Next

Rst.Close
dbConn.Close
Set Rst = Nothing
Set dbConn = Nothing

我的msn: myfend@
2006-12-19 12:02



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-110510-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.702735 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved