ADO如何将一个recordset中的所有数据复制到另外一个结构相同的表中

xiao_qiao 2004-09-15 07:42:10
如题
...全文
183 点赞 收藏 8
写回复
8 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
online 2004-09-16
Option Explicit
Private conn1 As ADODB.Connection
Private rs1 As ADODB.Recordset
Private conn2 As ADODB.Connection
Private rs2 As ADODB.Recordset

Private Sub Command3_Click()
Dim dbfilename As String
Dim strsql As String
Dim ConnectString As String
Dim i As Integer
Set conn1 = New ADODB.Connection
dbfilename = "F:\csdn_vb\database\listbox\article1.mdb"
ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbfilename & ";Persist Security Info=False;"
conn1.Open ConnectString

Set conn2 = New ADODB.Connection
dbfilename = "F:\csdn_vb\database\listbox\article2.mdb"
ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbfilename & ";Persist Security Info=False;"
conn2.Open ConnectString

Set rs1 = New ADODB.Recordset
Set rs2 = New ADODB.Recordset

strsql = "select * from mz"
rs1.Open strsql, conn1, 1, 3
rs2.Open strsql, conn2, 1, 3

For i = 0 To rs1.RecordCount - 1
rs2.AddNew
rs2.Fields("mc") = rs1.Fields("mc")
rs2.Fields("memo") = rs1.Fields("memo")
rs2.Update
rs1.MoveNext
Next
End Sub
回复
裸男 2004-09-15

用SQL语句快,如果非得用ADO的话,就只能一个字段一个字段地拷了。
回复
RUKYO 2004-09-15
你recordset的SQL查询语句是怎样的呀?例如这样:

strSQL = "Select * From Table3 Where Field3 = 123"

假设你recordset就是打开这条查询,那你可以把strSQL改成这样:

strSQL = "Select * Into Table1 From (Select * From Table3 Where Field3 = 123)"
回复
xiao_qiao 2004-09-15
没有更好的办法吗?
回复
harryho 2004-09-15
用两个recordset啦.
dim retsource as new adodb.recordset
dim retdec as new adodb.recordset
dim con as new adodb.connection
con.connectionstring="driver={sql server};server=;uid=sa;pwd=;database=数据库名称"
retsource.cursorlocation=adoclinet
retsource.open "select * from ",con
retdec.open "要插入的那个表"
for i= 0 to retsource.recordcount
retdec.addnew
for j=0 to retsoure.fields.count-1
retdec.fields(j)=retsource.fields(j)
next j
retdec.update
retsource.movenext
next i
搞掂.不过速度很慢.
建议用insert intto tablename select field1,field2 from tablename where....
回复
xiao_qiao 2004-09-15
不是从表中复制,是从一个recordset中
回复
northwolves 2004-09-15
SELECT * INTO newtable FROM oldtable
回复
RUKYO 2004-09-15
Select * Into Table2 From Table1 Where Field1 = 条件
回复
相关推荐
发帖

1188

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
帖子事件
创建了帖子
2004-09-15 07:42
社区公告
暂无公告