gpt4 book ai didi

mysql - 查找SQL表中的特定数据

转载 作者:行者123 更新时间:2023-11-30 01:10:37 26 4
gpt4 key购买 nike

我希望有人能帮助我解决这个问题,我是 SQL 新手,这让我感到困惑。我想通过输入框在 mySQL 表中查找特定/匹配的数据,此代码仅查找第一行中的数据,无法识别数据库行中的第二行和其余数据..

这是我的代码..

Dim rs As New ADODB.Recordset
myConn
Dim holdstr As String
holdstr = InputBox("Enter Number")
rs.Open "SELECT * FROM lemployees ", conn
Do Until rs.EOF

If holdstr = "" Then
conn.Close
Exit Sub
End If

If holdstr = rs!ENumber Then
MsgBox "Record found!", vbInformation, "Message"

UserForm2.lblnum.Caption = rs!ENumber
UserForm2.TextBox2.Text = rs!ELName
UserForm2.TextBox3.Text = rs!EFName
UserForm2.TextBox4.Text = rs!EMName
UserForm2.boxPos = rs!EDepartment
UserForm2.TextBox6.Text = rs!EAge
UserForm2.TextBox7.Text = rs!EHourlyPaid
UserForm2.TextBox8.Text = rs!ECitizen

conn.Close
Exit Sub
Else
MsgBox "Record not found", vbInformation, "Message"
Exit Sub
End If
Loop

谢谢!

最佳答案

您退出循环内的 Sub。即使没有找到您要查找的项目。

尝试

Dim rs As New ADODB.Recordset
myConn
Dim holdstr As String
holdstr = InputBox("Enter Number")

If holdstr = "" Then
Exit Sub
End If

rs.Open "SELECT * FROM lemployees ", conn
Do Until rs.EOF
If holdstr = rs!ENumber Then
MsgBox "Record found!", vbInformation, "Message"

UserForm2.lblnum.Caption = rs!ENumber
UserForm2.TextBox2.Text = rs!ELName
UserForm2.TextBox3.Text = rs!EFName
UserForm2.TextBox4.Text = rs!EMName
UserForm2.boxPos = rs!EDepartment
UserForm2.TextBox6.Text = rs!EAge
UserForm2.TextBox7.Text = rs!EHourlyPaid
UserForm2.TextBox8.Text = rs!ECitizen

conn.Close
Exit Sub
End If
Loop
MsgBox "Record not found", vbInformation, "Message"
conn.Close
Exit Sub

关于mysql - 查找SQL表中的特定数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19491002/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com