代码如下: 这段代码是有错误的,我每次找到的都是符合条件的第一条记录 我想找到所有符合条件的记录该怎么找 大家帮我看一下
Private Sub Command1_Click()
Dim names As String
dim rec as new adodb.recordset
Dim i As Integer
i = 0names = Form1.Text2.Text
rec.Open "select * from pinfo where dir like '%" & sname & "%'", con, adOpenKeyset, adLockOptimistic
z:
If Not rec.EOF And rec.RecordCount <> 0 Then
i = 1
List1.AddItem rec("pname")
rec.Close
rec.Open "select * from pinfo where dir like '%" & sname & "%'", con, adOpenKeyset, adLockOptimistic
GoTo z:
Else
If i = 0 Then '如果一条没找到
MsgBox "没有找到符合条件的照片,请重新输入", vbOKOnly, "查找照片"
End If
rec.Close
Exit Sub
End If
Private Sub Command1_Click()
Dim names As String
dim rec as new adodb.recordset
Dim i As Integer
i = 0names = Form1.Text2.Text
rec.Open "select * from pinfo where dir like '%" & sname & "%'", con, adOpenKeyset, adLockOptimistic
z:
If Not rec.EOF And rec.RecordCount <> 0 Then
i = 1
List1.AddItem rec("pname")
rec.Close
rec.Open "select * from pinfo where dir like '%" & sname & "%'", con, adOpenKeyset, adLockOptimistic
GoTo z:
Else
If i = 0 Then '如果一条没找到
MsgBox "没有找到符合条件的照片,请重新输入", vbOKOnly, "查找照片"
End If
rec.Close
Exit Sub
End If
每次打开的时候不都直接select了吗\
i = 1
do while not rec.eof
List1.AddItem rec("pname")
rec.movenext
loop
rec.Close
dim rec as new adodb.recordset
Dim i As Integer
i = 0 names = Form1.Text2.Text
rec.CursorLocation = adUseClient
rec.Open "select * from pinfo where dir like '%" & sname & "%'", con, adOpenKeyset, adLockOptimistic'z:
if rec.recordcount<>0 then
do while not rec.eof
'If Not rec.EOF And rec.RecordCount <> 0 Then
' i = 1
List1.AddItem rec("pname")
rec.movenext
loop
' rec.Close
' rec.Open "select * from pinfo where dir like '%" & sname & "%'", con, adOpenKeyset, adLockOptimistic
' GoTo z:
Else
'If i = 0 Then '如果一条没找到
MsgBox "没有找到符合条件的照片,请重新输入", vbOKOnly, "查找照片"
End If
rec.Close
'Exit Sub
End If你这样试试!!!
ling242a() 是这样的 好比说我想找"pname"字段中含"names"的记录 然后把找到的所有记录添加的list中
对了 这么定义的的那个names错了 应该是sname对了 select的语句是只找到一个记录吗?还是找出所有的
我就想找到这个表中所有"pname"字段中含"names"的记录 该怎么写select呢
Private Sub Command1_Click()
Dim sname As String
dim rec as new adodb.recordset
Dim i As Integer
i = 0sname = Form1.Text2.Text
rec.Open "select * from pinfo where pname like '%" & sname & "%'", con, adOpenKeyset, adLockOptimistic
do until rec.eof
list1.additem rec("pname")
rec.movenext
loop
rec.Close
End Sub
而且movenext是移动找到的记录 不是顺序移动记录 明白了