iamnamja
asked on
Insert ADO recordset to table
Hi,
I have a VBA that queries a database and gets a set of data into a recordset. I need a way to copy this data into the table. The recordset and the table both have a same structure (1 column) and the recordset is usually large (100,000 rows) and the table is cleared before it is filed with the data.
Any way I can do an insert that copies whole recordset into table?
I've seen lots of examples where we go through each recordset and do an insert, but due to the size, i can't imagine this method being efficient.
I have a VBA that queries a database and gets a set of data into a recordset. I need a way to copy this data into the table. The recordset and the table both have a same structure (1 column) and the recordset is usually large (100,000 rows) and the table is cleared before it is filed with the data.
Any way I can do an insert that copies whole recordset into table?
I've seen lots of examples where we go through each recordset and do an insert, but due to the size, i can't imagine this method being efficient.
ASKER
Hi Jim,
Could you give me an example of how this would work?
Here's my current code inserting line by line..
Could you give me an example of how this would work?
Here's my current code inserting line by line..
all_SQL = "SELECT distinct i.sid " & _
"FROM common..idlist i"
Set all_RS = query_DB(globconn, all_SQL)
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE * FROM Latest_TIDs"
DoCmd.SetWarnings True
If all_RS.State <> 0 Then
If Not (all_RS.EOF And all_RS.BOF) Then
all_RS.MoveFirst
DoCmd.SetWarnings False
Do While Not all_RS.EOF
DoCmd.RunSQL "INSERT INTO Latest_SIDs (sid) VALUES(""" & all_RS!sid.Value & """)"
all_RS.MoveNext
Loop
DoCmd.SetWarnings True
End If
End If
all_SQL = "INSERT INTO Latest_SIDs ( SID ) SELECT distinct i.sid FROM common..idlist i"
CurrentDB.Execute all_SQL, dbFailOnError
This assumes the tables are available as linked tables as with CurrentDB().Execute or DoCmd.RunSQL, you are not using ADO to execute the query (linked tables use ODBC).
Jim.
CurrentDB.Execute all_SQL, dbFailOnError
This assumes the tables are available as linked tables as with CurrentDB().Execute or DoCmd.RunSQL, you are not using ADO to execute the query (linked tables use ODBC).
Jim.
ASKER
Hi Jim,
Unfortunately the tables are NOT linked - actually can't be linked, so i would need to query it the way I did above. Does that mean the only method is the way that I have currently written?
Unfortunately the tables are NOT linked - actually can't be linked, so i would need to query it the way I did above. Does that mean the only method is the way that I have currently written?
<<Unfortunately the tables are NOT linked ->>
I don't understand how your RunSQL works then.
Jim.
I don't understand how your RunSQL works then.
Jim.
<<Does that mean the only method is the way that I have currently written? >>
missed this...no, you can execute the SQL via ADO:
<connection object>.Execute all_SQL
Jim.
missed this...no, you can execute the SQL via ADO:
<connection object>.Execute all_SQL
Jim.
ASKER
So just so that we're on the same page... The all_rs query is run on a sybase database and the recordset data fetched is what i need to store into my table called Latest_SIDs.
How do i run a query that inserts a data from a sybase database into access?
How do i run a query that inserts a data from a sybase database into access?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I don't understand why you can't link the table. The link doesn't need to be permanent. You can use TransferDatabase to link and then delete the link when you are done.
A linked table is faster performance wise too...
Jim.
Jim.
In short, no. But what you can do is execute an INSERT with a SELECT based on the one you just used to get the record set.
Jim.