[英]VB6 Search Recordset
我正在運行一個程序,該程序通過Access數據庫驗證文本字段的輸入。 這是一個示例代碼:
Private Sub TextBox_LostFocus()
If TextBox <> "" Then
With recordset
.Index = "PrimaryKey"
.Seek "=", TextBox
If .NoMatch Then
MsgBox "Record does not exist!", vbExclamation, Me.Caption
TextBox = ""
TextBox.SetFocus
End If
End With
End If
End Sub
我總是收到“ PrimaryKey”不是索引的錯誤。 我需要幫助。
差點忘了。 這是加載表單時的代碼:
Private Sub Form_Load()
CenterForm
Me.Top = 0
Set database = OpenDatabase("p:\location\file.mdb")
Set recordset = database.OpenRecordset("table")
End Sub
在數據庫內部,您必須將字段PrimaryKey定義為索引。
請在此處查看Microsoft的文檔:
至於查找/索引檢查...請嘗試以下操作:
嘗試這個:
Private Sub TextBox_LostFocus()
If TextBox <> "" Then
If NOT recordset.Supports(adIndex) THEN MSGBOX("AdIndex not supported")
IF NOT recordset.Supports(adSeek) Then MSGBOX("adSeek not supported")
With recordset
.Index = "PrimaryKey"
.Seek "=", TextBox
If .NoMatch Then
MsgBox "Record does not exist!", vbExclamation, Me.Caption
TextBox = ""
TextBox.SetFocus
End If
End With
End If
End Sub
這將告訴您使用您提供的提供商是否允許搜索或索引。 切換OLE提供程序可能是您的答案。
沒有索引就可以完成搜索方法嗎? 如果是這樣,怎么辦?
不,尋求需要索引。 但是您可以遍歷所有記錄。 根據記錄的數量,這可能是一個嚴重的性能問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.