VB 两个access表,两个表的字段相同,其中一个表的数据插入另一个表,遇到相同的数据就跳过不插入,求代码

来源:百度知道 编辑:UC知道 时间:2024/05/04 04:13:09

'连接数据库
rs.open "select * from [表1]",conn,1,1
if rs.eof and rs.bof then
rs.close
msgbox "结束"
else
while not rs.eof
rs1.open "select * from [表2] where 字体1='"& rs.Fields("字段1")&"'",conn,1,3
if rs1.eof and rs1.bof then
rs1.addnew
rs1.Fields("字段1")=rs.Fields("字段1")
rs1.Fields("字段2")=rs.Fields("字段2")
...
rs1.update
rs1.close
end if
rs.movenext
wend
end if
msgbox "结束"

dim iRecordCount as integer'byte 也可以
if Rs1.RecordCount > Rs2.RecordCount then
iRecordCount=Rs2.recordCount
else
iRecordCount=R1.recordCount
end if
for i=1 to iRecordCount
if Rs1.fields("field")<>Rs2.fields("field")then
conn.execute("update rs2tablename set rs2field=rs1field where id="&i)'rs1field 就是你的字段名
en