VB中如何判断数值在表中是否存在,不难,大虾门帮下啊~

来源:百度知道 编辑:UC知道 时间:2024/06/28 13:07:40
比如我在text中输入了一个数值,我想判断这个数值在table表的num列中是否存在,该如何实现?
类似SQL中的exists函数的最好

dim rs as new adodb.recordset
rs.open "select * from table where num =" & text1.text ,cnn
if rs.eof then
'不存在
else
'存在
endif

rs.close

Rs.Open "select num from table where num=like '*" & text1.text & "*'"
if Rs.Eof=true '说明没有找到
或者 if Rs.RecordCount=0 也说明不存在

like 后面的 * 是Access中使用的通配符,在其它数据库中,应该是 %