当前位置:编程学习 > VB >>

vb向access写入新表的问题

用select语句筛选数据库中表1的数据后,想将其写入数据库中表2,并在退出时清空,恢复表2空的状态,请问该怎样写代码呢? insert into 表2 (id,stu_name,stu_phone) select id,stu_name,stu_phone from 表1 where id < 30 delete from 表2 select * from Table1 --选取适当列
into Table2 
where Table1.col=XX  --选择条件 insert into 表2 select * from 表1
delete * from 表2
引用 4 楼 dbcontrols 的回复:
insert into 表2 select * from 表1
delete * from 表2


同意此方法 建议:

使用时直接生成表2
select * into 表2 from 表1 where ...
退出时直接删除表2
DROP TABLE 表2
先建临时表(字段)
insert into tb select * from tb1 where ....
delete from tb........ select * from 表1 where 条件


do while not rs.eof

开始显示在表格上

insert into 表  (字段1,字段2) value('" & rs.fields("字段1") &"' ,'" & rs.fields("字段2") &"' )
conn.Execute SqlStr   '这个一定要加 不然不执行

rs.movenext
loop


你肯定是在窗口退出时 清空 表2
那就用
delete * from 表2 不是将表1的数据复制到表2中,是将筛选后的数据填入表2,
Adodc1.RecordSource = "select * from 涂装计划 where 计划生产时间 between #" & DTPicker1.Value & "# and #" & DTPicker2.Value & "#"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
是这样实现的,这样写也可以吗?
引用 4 楼 dbcontrols 的回复:
insert into 表2 select * from 表1
delete * from 表2

strsql="intsert into table2 select * from 涂装计划 where 计划生产时间 between #" & DTPicker1.Value & "# and #" & DTPicker2.Value & "#"

建议用adodb来做 adodb
参考

vb怎么和access连接 其实我是想将筛选后的数据存在表2中,然后通过text控件的datasource和datafield属性跟ado或者data连接起来,然后实现能逐一查询数据的功能,用sql的话,不行吧。
引用 10 楼 jjhhgg1111 的回复:
strsql="intsert into table2 select * from 涂装计划 where 计划生产时间 between #" & DTPicker1.Value & "# and #" & DTPicker2.Value & "#"
建个临时表,可以实现的 我完全糊涂中,大师们,教我吧,非常感谢,分分送上
引用 14 楼 dbcontrols 的回复:
建个临时表,可以实现的
补充:VB ,  数据库(包含打印,安装,报表)
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,