新手小白 求教连接数据库问题
想连接 MS SQL 数据库,然后返回一个列表,用datagrid控件,有数据,但是用DATACOMBO控件就没数据 应该怎么写代码Private Sub dataCombo1_GotFocus()
dim conn as adodb.connection
dim rst as adodb.recordset
Set Conn = New ADODB.Connection '数据库对象的实例化
Set Rst = New ADODB.Recordset '记录集对象的实例化
Conn.CursorLocation = adUseClient
Conn.Open "Provider=SQLOLEDB.1;Password=Pei%791128;Persist Security Info=True;User ID=sa;Initial Catalog=master;Data Source=192.168.11.252"
'执行 ADODB.Recordset对象的Open方法,获得记录集
Rst.Open "Select cacc_name From t_kdaccount_gl", Conn, adOpenKeyset, adLockPessimistic
'将返回的记录集显示到Datacombo1
Set dataCombo1.DataSource = Rst
Set Rst = Nothing '释放记录集对象
Set Conn = Nothing '释放数据库对