1. 程式人生 > >ADODC控制元件簡單應用示例

ADODC控制元件簡單應用示例

Dim strinp As String
Dim msgint As Integer
Dim intlen As Integer
strinp = InputBox("請輸入您要查詢的IMEI", "入庫記錄查詢")
intlen = Len(strinp)
If strinp = "" Then
msgint = MsgBox("實在是佩服,空的IMEI號也要查詢!請重新輸入要查詢的IMEI", vbOKOnly, "致詞")
Exit Sub
End If
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "/apkf.mdb;Persist Security Info=False"
Adodc1.CommandType

= adCmdText
Adodc1.RecordSource = "select * from [apkf] where right(imei," & intlen & ")= '" & strinp & "'"
Adodc1.Refresh

參考:

Private Sub Adodc1_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
Text1.Text = Adodc1.Recordset.Fields("name")
End Sub

Private Sub DataGrid1_Click()
Text1.Text = Adodc1.Recordset.Fields("name")
End Sub

Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Program Files/Microsoft Visual Studio/VB98/BIBLIO.MDB;Persist Security Info=False"
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = "select * from Publishers"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
End Sub