VB+Access实例:使用ADO连接Access数据库。Private Sub Form_Load()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db_medicine.MDB"
rs.Open "tb_kc", cn, adOpenKeyset, adLockOptimistic 'adOpenKeyset打开键集类型游标。adLockOptimistic开放式锁定(逐个) — 提供者使用开放式锁定,只在调用Update 方法时才锁定记录
Set MSHFlexGrid1.DataSource = rs
MSHFlexGrid1.ColWidth(0) = 0 '返回或设置指定带区中的列宽
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
End Sub
1