neoartz237
Tensai
- Local time
- Today, 15:44
- Joined
- Feb 12, 2007
- Messages
- 65
I want to copy a table from Oracle through ADODB Connection.
I did an early draft of of it but its runs so slow.
I have 11 tables: Here's my code:
Dim conn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rst As ADODB.Recordset
Dim tblNames(1 To 11) As String
Dim newName, InsStr, strModifier, connStr As String
Dim i, c, d As Integer
'////Fill up tables array////
tblNames(1) = "TKYOKUMD01"
tblNames(2) = "TTOKUKMD01"
tblNames(3) = "TTOKUIMD01"
tblNames(4) = "TSIHARMD01"
tblNames(5) = "TTORIKMD01"
tblNames(6) = "TSERMEMD01"
tblNames(7) = "TKANKAMD01"
tblNames(8) = "TSWKMSTD01"
tblNames(9) = "TUKKMKMD01"
tblNames(10) = "TCALENMD01"
tblNames(11) = "TSEKYUMD01"
For i = 1 To 11
If doChecker(tblNames(i)) Then
Set cmd = Nothing
Set rst = Nothing
Set conn = New ADODB.Connection
Set cmd = New ADODB.Command
conn.Open restorConStr '<<<----- check mdlConnection Module
DoCmd.RunSQL ("DELETE * FROM " & tblNames(i))
cmd.ActiveConnection = conn
cmd.CommandType = adCmdTable
cmd.CommandText = tblNames(i)
Set rst = cmd.Execute
If rst.RecordCount <> 0 Then
Do While Not rst.EOF
InsStr = ""
c = rst.Fields.Count
For d = 0 To c - 1
'////Check if Numeric or not////
If rst.Fields(d).Type = adNumeric Then
If Len(rst.Fields(d).Value) > 255 Then
strModifier = Mid(rst.Fields(d).Value, 1, 255)
Else
strModifier = rst.Fields(d).Value
End If
Else
If Len(rst.Fields(d).Value) > 255 Then
strModifier = "'" & Mid(rst.Fields(d).Value, 1, 255) & "'"
Else
strModifier = "'" & rst.Fields(d).Value & "'"
End If
End If
If d <> c - 1 Then
InsStr = InsStr & strModifier & ","
Else
InsStr = InsStr & strModifier
End If
Next d
DoCmd.RunSQL ("INSERT INTO " & tblNames(i) & " VALUES (" & InsStr & ")")
rst.MoveNext
Loop
End If
End If
Next i
Set rst = Nothing
Now, it works perfectly and runs no errors, but it takes almost 10 minutes to complete. I figure, if I can copy the tables from the recordset since that I declared it as table in :
"cmd.CommandType = adCmdTable
md.CommandText = tblNames(i)
Set rst = cmd.Execute"
Maybe I can copy it then use INSERT SELECT because as we all know thats much more efficient and faster. Please help
I did an early draft of of it but its runs so slow.
I have 11 tables: Here's my code:
Dim conn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rst As ADODB.Recordset
Dim tblNames(1 To 11) As String
Dim newName, InsStr, strModifier, connStr As String
Dim i, c, d As Integer
'////Fill up tables array////
tblNames(1) = "TKYOKUMD01"
tblNames(2) = "TTOKUKMD01"
tblNames(3) = "TTOKUIMD01"
tblNames(4) = "TSIHARMD01"
tblNames(5) = "TTORIKMD01"
tblNames(6) = "TSERMEMD01"
tblNames(7) = "TKANKAMD01"
tblNames(8) = "TSWKMSTD01"
tblNames(9) = "TUKKMKMD01"
tblNames(10) = "TCALENMD01"
tblNames(11) = "TSEKYUMD01"
For i = 1 To 11
If doChecker(tblNames(i)) Then
Set cmd = Nothing
Set rst = Nothing
Set conn = New ADODB.Connection
Set cmd = New ADODB.Command
conn.Open restorConStr '<<<----- check mdlConnection Module
DoCmd.RunSQL ("DELETE * FROM " & tblNames(i))
cmd.ActiveConnection = conn
cmd.CommandType = adCmdTable
cmd.CommandText = tblNames(i)
Set rst = cmd.Execute
If rst.RecordCount <> 0 Then
Do While Not rst.EOF
InsStr = ""
c = rst.Fields.Count
For d = 0 To c - 1
'////Check if Numeric or not////
If rst.Fields(d).Type = adNumeric Then
If Len(rst.Fields(d).Value) > 255 Then
strModifier = Mid(rst.Fields(d).Value, 1, 255)
Else
strModifier = rst.Fields(d).Value
End If
Else
If Len(rst.Fields(d).Value) > 255 Then
strModifier = "'" & Mid(rst.Fields(d).Value, 1, 255) & "'"
Else
strModifier = "'" & rst.Fields(d).Value & "'"
End If
End If
If d <> c - 1 Then
InsStr = InsStr & strModifier & ","
Else
InsStr = InsStr & strModifier
End If
Next d
DoCmd.RunSQL ("INSERT INTO " & tblNames(i) & " VALUES (" & InsStr & ")")
rst.MoveNext
Loop
End If
End If
Next i
Set rst = Nothing
Now, it works perfectly and runs no errors, but it takes almost 10 minutes to complete. I figure, if I can copy the tables from the recordset since that I declared it as table in :
"cmd.CommandType = adCmdTable
md.CommandText = tblNames(i)
Set rst = cmd.Execute"
Maybe I can copy it then use INSERT SELECT because as we all know thats much more efficient and faster. Please help