VB 查询数据库某一字段的所有内容

查询姓名字段的所有内容,如果内容为zy,那么计数,每出现一次就加1,请问代码怎么写

dim i as long '计数
dim conn as new adodb.connention
dim rs as new adodb.recordset
private sub commad1_click()
rs.Open "select * from table", conn, adOpenKeyset, adLockOptimistic
if rs.RecordCount<> 0 then '查询数据库是否为空
for i=0 to rs.RecordCount-1
if zy=rs.filed("姓名") then '判断所查数据是否等于zy
i=i+1 '等于则计数加一
endif
rs.movenext
next i
enif
end sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-07-05
如果新建一个自动编号(递增)字段的话,则不必写ADO,在查询QBE新建一个字段即可:
计数:Dcount("姓名","表","姓名='xy' and 编号<="&[编号])
第2个回答  2020-03-07
dim
i
as
long
'计数
dim
conn
as
new
adodb.connention
dim
rs
as
new
adodb.recordset
private
sub
commad1_click()
rs.Open
"select
*
from
table",
conn,
adOpenKeyset,
adLockOptimistic
if
rs.RecordCount<>
0
then
'查询数据库是否为空
for
i=0
to
rs.RecordCount-1
if
zy=rs.filed("姓名")
then
'判断所查数据是否等于zy
i=i+1
'等于则计数加一
endif
rs.movenext
next
i
enif
end
sub