将Complete RecordSet插入到其他数据库MS Access中的另一个表 [英] Insert Complete RecordSet to another table in other database MS Access
问题描述
我在两个不同的文件中有2个表,它们具有相同的列.我要从另一个文件"Sanchez_Mar.mdb"插入所有Recordset的一个文件"Base PT.accdb".两个表都有7个名称相同的列.
I have 2 Tables with same colums in two diferent files. One file "Base PT.accdb" where i want to insert all the Recordset from the other file "Sanchez_Mar.mdb". Both tables have 7 Columns with the same name.
我在使用"System.Data.OleDb.OleDbConnection"时遇到很多问题,因此我决定使用RecordSets. 目前,我正在使用循环插入所有内容,但是数据很多,因此需要很长时间. 是否可以将所有记录集插入另一个数据库?
I had a lot of problems using "System.Data.OleDb.OleDbConnection" so i decided to use RecordSets. At the moment i'm using loop to insert all, but there is a lot of data so it take quite long. It's posible to insert all the recordset to the other database ?
这是我需要帮助的代码的一部分:
this is the part of my code i need help:
Sub Copiar_BasePT2(RutaPT As String)
Dim Cant as Long
Dim db As Database
Dim dbBase_PT As Database
Set dbBase_PT = OpenDatabase(RutaPT & "\Base PT.accdb")
Set db = CurrentDb
Dim rsSYM As Recordset
Set rsSYM = db.OpenRecordset("SELECT * from FINAL_Alarma_SYM")
rsSYM.MoveLast
Cant = rsSYM.RecordCount
rsSYM.MoveFirst
For i = 1 To Cant
dbBase_PT.Execute ("Insert into Tab_PT values('" & rsSYM.Fields(0) & "','" & rsSYM.Fields(1) & "','" & rsSYM.Fields(2) & "','" & rsSYM.Fields(3) & "','" & rsSYM.Fields(4) & "','" & rsSYM.Fields(5) & "','" & rsSYM.Fields(6) & "');")
rsSYM.MoveNext
DoEvents
Next i
End Sub
是否可以插入所有记录集? 或者如何将表从"Sanchez_Mar.mdb"更快地移至"Base PT.accdb"?
It is posible to insert all the recordset ? Or how can I bring the table From "Sanchez_Mar.mdb" to "Base PT.accdb" faster?
推荐答案
您可以使用其他数据库作为数据源来运行插入查询.
You can run an insert query using your other database as the source for the data.
"INSERT INTO Tab_PT (Field1, Field2, Field3, Field4, Field5, Field6, Field7) " & _
" SELECT Field1, Field2, Field3, Field4, Field5, Field6, Field7 " & _
" FROM [MS Access;DATABASE=PathToSanchez_MarDB].FINAL_Alarma_SYM"
这篇关于将Complete RecordSet插入到其他数据库MS Access中的另一个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!