在数据库中的查找方式

本文介绍了使用VBA在不同类型的数据库组件(如dbcombo、dblist、datacombo、datalist及adodc等)中实现姓名查询的具体方法。通过实际代码示例展示了如何根据输入的姓名在数据库中进行搜索,并反馈查询结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在dbcombo、dblist、datacombo、datalist中用以下方式:

' 查询
Private Sub cmdserch_Click()
Dim x As String
'定义查找方式
DBList1.MatchEntry = dblBasicMatching
x = InputBox("请输入要查询的姓名", "查询", DBList1.Text)
If Trim(x) = vbNullString Then Exit Sub
DBList1.Text = x
If Not (DBList1.MatchedWithList) Then
MsgBox "数据库中没有姓名为“" & x & "”的记录", vbExclamation, "查找"
Else
Text1.Text = DBList1.BoundText
End If
End Sub

在 adodc中

' 查询
Private Sub cmdserch_Click()
Dim x As String
x = InputBox("请输入要查询的姓名", "查询")
If Trim(x) = vbNullString Then Exit Sub
adodc1.Recordset.Find "姓名" & "=" & "'" & x & "'"
If adodc1.Recordset.EOF Then
MsgBox "数据库中没有姓名为“" & x & "”记录", vbExclamation, "查找"
End If
End Sub

在 data中

' 查询
Private Sub cmdserch_Click()
Dim texfind As String
texfind = InputBox("请输入要查询的姓名", "查询")
If Trim(texfind) = vbNullString Then Exit Sub
' 进行根据选择条件查询
Data1.Recordset.FindFirst "姓名" & "=" & "'" & texfind & "'"
' 如果没有找到记录NoMatch的值为True,找到记录NoMatch的值为False
If Data1.Recordset.NoMatch = True Then
MsgBox "数据库中没有姓名为“" & texfind & "”的记录", vbExclamation, "查找"
End If
End Sub 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值