没有数据库...那当然不能连接..
我的msn: myfend@
[此贴子已经被作者于2006-12-10 14:18:26编辑过]
Private Sub Combo1_Click()
Dim sql As String
sql = "select [H] from Tdata1 where [Name]='" & Trim(Combo1.Text) & "'"
If Rst.State = adStateOpen Then Rst.Close
Rst.Open sql, dbConn, adOpenKeyset, adLockPessimistic, adCmdText
Text1.Text = Rst.Fields("H").Value
End Sub
Private Sub Form_Load()
Dim conString As String
conString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" & App.Path & "\db.mdb"
Set dbConn = CreateObject("ADODB.Connection")
With dbConn
.ConnectionString = conString
.Open
End With
Set Rst = CreateObject("ADODB.Recordset")
Rst.CursorLocation = adUseClient
Dim sql As String
sql = "select [Name] from Tdata1"
Rst.Open sql, dbConn, adOpenKeyset, adLockPessimistic, adCmdText
Dim lngRecordCount As Long
Rst.MoveLast
lngRecordCount = Rst.RecordCount
Rst.MoveFirst
Dim i As Long
For i = 0 To lngRecordCount - 1
Combo1.AddItem Rst.Fields("Name").Value
Rst.MoveNext
Next
Combo1.ListIndex = 0
End Sub
Private Sub Form_Unload(Cancel As Integer)
Rst.Close
dbConn.Close
Set Rst = Nothing
Set dbConn = Nothing
End Sub