vb删除数据库符合条件的数据

2025-04-15 15:30:29
推荐回答(1个)
回答1:

******的代码如下:

Dim rs As ADODB.Recordset
SqlStr="select 身份证号 from 表 where 信息类型=路考 and 信息说明=合格"

set rs = cn.Execute(sql)'执行语句

if not rs.eof then '如果存在记录
for i = 0 to rs.RecordCount - 1
SqlStr="delete 表 where 身份证号 = '" & rs(i)("身份证号")
cn.Execute sql
SqlStr="delete 另外一个表 where 身份证号 = '" & rs(i)("身份证号")
cn.Execute sql
rs.MoveNext
next i
end if
set rs=nothing