[200很简单]access数据库中查询后如何存入表中? ( 积分: 200 )

  • 主题发起人 主题发起人 liugaohui
  • 开始时间 开始时间
L

liugaohui

Unregistered / Unconfirmed
GUEST, unregistred user!
用access数据库,有两个表a表和b表,a表和b表结构完全相同,用ADOQuery1对a表进行查询,将符合要求的记录写入b表,当然写入前清空b表的以前记录<br><br><br>谢谢回复!
 
delete&nbsp;table&nbsp;b<br>insert&nbsp;into&nbsp;b&nbsp;(field1,field2,field3)&nbsp;select&nbsp;field1,field2,field3&nbsp;from&nbsp;a&nbsp;where&nbsp;条件
 
select&nbsp;*&nbsp;<br>into&nbsp;B表<br>from&nbsp;A表<br>where.......
 
出错呀,不知道为什么?
 
可以用循环的方式来增加
 
(1)&nbsp;&nbsp;delete&nbsp;table&nbsp;b<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select&nbsp;*&nbsp;into&nbsp;b&nbsp;from&nbsp;a&nbsp;where&nbsp;条件<br>(2)&nbsp;&nbsp;delete&nbsp;from&nbsp;b<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;insert&nbsp;into&nbsp;b&nbsp;select&nbsp;*&nbsp;from&nbsp;a&nbsp;where&nbsp;条件
 
with&nbsp;ADOQuery1&nbsp;do<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;sql.Clear;<br>&nbsp;&nbsp;sql.Add('delete&nbsp;*&nbsp;from&nbsp;表b);<br>&nbsp;&nbsp;sql.Add('insert&nbsp;into&nbsp;表b&nbsp;select&nbsp;*&nbsp;from&nbsp;表a&nbsp;where&nbsp;&nbsp;。。。。。。');<br>&nbsp;&nbsp;execsql;<br>&nbsp;&nbsp;active:=true;<br>&nbsp;&nbsp;end;<br><br>1、怎么判断已经经是空表,如果已经是空表,是不是删除就会出错?<br>2、添加时为什么总是说主键等有重复?<br>3、谢谢以上各位朋友!<br>4、谢谢回复!<br>请问为什么总出错呢?
 
老大,你要先删除了在添加呀<br>with&nbsp;ADOQuery1&nbsp;do&nbsp;&nbsp;begin<br>&nbsp;&nbsp;close;<br>&nbsp;&nbsp;sql.Clear;<br>&nbsp;&nbsp;sql.Add('delete&nbsp;*&nbsp;from&nbsp;b);<br>&nbsp;&nbsp;execsql;<br><br>&nbsp;&nbsp;close;<br>&nbsp;&nbsp;sql.clear;<br>&nbsp;&nbsp;sql.Add('insert&nbsp;into&nbsp;b&nbsp;select&nbsp;*&nbsp;from&nbsp;a&nbsp;where&nbsp;&nbsp;。。。。。。');<br>&nbsp;&nbsp;execsql;<br><br>&nbsp;&nbsp;close;<br>&nbsp;&nbsp;sql.clear;<br>&nbsp;&nbsp;sql.Add('select&nbsp;*&nbsp;from&nbsp;b');<br>&nbsp;&nbsp;open;<br>&nbsp;end;
 
楼上也不全对,<br>delete&nbsp;*&nbsp;from&nbsp;b,这是错误的,&nbsp;应该是delete&nbsp;from&nbsp;b&nbsp;即把b表清空
 
多人接受答案了。
 
后退
顶部