怎么将Access的值添加到VB 中combo的list中
假设access数据库db中有表finfans,中有三个字段type,a,和b,怎么把type(文本型)下的值在combo中全部显示出来?请用简单的代码表示下,谢谢!...
假设access数据库db中有表finfans,中有三个字段type,a,和b,怎么把type(文本型)下的值在combo中全部显示出来?请用简单的代码表示下,谢谢!
展开
2014-02-16
展开全部
Public appdisk As String
Public conn As New ADODB.Connection
Public Rs As New ADODB.Recordset
Public db As String
Private sSQL As String
Private Sub Form_Load()
On Error GoTo Err
appdisk = Trim(App.Path)
If Right(appdisk, 1) <> "\\" Then appdisk = appdisk & "\\"
db = appdisk
db = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & db & "db.mdb" '获取MDB数据库路径
conn.CursorLocation = adUseClient
conn.Open db
Rs.Open "select * from finfans", conn, adOpenKeyset, adLockPessimistic
If Rs.EOF = False Then
Do Until Rs.EOF
Combo1.AddItem Rs!type
Rs.MoveNext
Loop
End If
Rs.Close: Set Rs = Nothing
exit sub
Err:
MsgBox Err.Number
Unload Me
End Sub
Public conn As New ADODB.Connection
Public Rs As New ADODB.Recordset
Public db As String
Private sSQL As String
Private Sub Form_Load()
On Error GoTo Err
appdisk = Trim(App.Path)
If Right(appdisk, 1) <> "\\" Then appdisk = appdisk & "\\"
db = appdisk
db = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & db & "db.mdb" '获取MDB数据库路径
conn.CursorLocation = adUseClient
conn.Open db
Rs.Open "select * from finfans", conn, adOpenKeyset, adLockPessimistic
If Rs.EOF = False Then
Do Until Rs.EOF
Combo1.AddItem Rs!type
Rs.MoveNext
Loop
End If
Rs.Close: Set Rs = Nothing
exit sub
Err:
MsgBox Err.Number
Unload Me
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询