?
Solved

Quickly Add 10000 records to Access 2000

Posted on 2001-08-16
12
Medium Priority
?
222 Views
Last Modified: 2008-02-01
I am currently developing a VB6 program where, at one point, I need to add 10000 records to a table. Right now what I am doing is basically:

dim rs as new adodb.recordset

rs.Open "select * from TABLE1", sConnection, adOpenKeyset, adLockOptimistic

For i = 1 to 10000
   rs.addnew
   rs(0).value = "blah"
   rs(1).value = "blah blah"
   rs.update
Next i

This method is proving to be very very slow. Is there any other way to do this? Maybe some kind of batch import? Any suggestions/ideas will be welcome.
0
Comment
Question by:dougtimms
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 1

Accepted Solution

by:
kdg2000 earned 400 total points
ID: 6391697
The batch addition of records is possible.
Approximately so:

Dim rstTitles As ADODB.Recordset
  Set rstTitles = New ADODB.Recordset
   rstTitles.CursorType = adOpenKeyset
   rstTitles.LockType = adLockBatchOptimistic
   rstTitles.Open "select * from TABLE1", sConnection, , , adCmdTable
   rstTitles.MoveFirst
   '
   Do Until rstTitles.EOF
        rstTitles(0).Value = "blah"
        rstTitles(1).Value = "blah blah"
   Loop
   If MsgBox("Save all changes?", vbYesNo) = vbYes Then
      rstTitles.UpdateBatch
   Else
      rstTitles.CancelBatch
   End If

End Sub
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6391702
<listening..>
0
 
LVL 6

Expert Comment

by:VK
ID: 6391731
hello,

try rs.execute ("....")
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:VK
ID: 6391734
of course : adodb.execute
0
 

Expert Comment

by:ibrahim-darahem
ID: 6391786
try this

Private Sub Command1_Click()
Dim rs As New ADODB.Recordset
sConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\TestDb.mdb;Persist Security Info=False"
rs.Open "select * from TABLE1", sConnection, adOpenKeyset, adLockOptimistic

x = Timer
For i = 1 To 10000
  rs.AddNew Array("field1", "field2"), Array("blah", "blah blah")
  rs.Update
Next i

MsgBox (Timer - x)
End Sub
0
 
LVL 39

Expert Comment

by:appari
ID: 6391791
seeing your code it seems duplicate values is not a problem. in that cae you can try the following.

add one record manually
then run the following code

dim intCount as integer
dim strSQL as string
for intCount = 1 to 12
    strSQL = "insert into Table1 Select * from Table1"
    sconnection.execute strSQL
next intCount

by the time u comeout of for loop you should have about 16000 records in your table.

0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6392021
ibrahim-darahem, you are relatively new to this site so I would ask you to please read the guidelines on comments vs answers at the bottom of this page and on http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp 

It is not considered good practice to lock questions in this way, as this places these questions in the locked section and reduces the visibility of the question to other experts. It also tends to put pressure on the questioner to accept the proposed answer. In future, please do not post "answers" except in trivial questions which have one and only one answer such as what is 1+1. I know that is a bit simplistic but I am sure you get the idea.

If you continue to post answers, you will a) get some far more severe reactions from less tolerant experts, b) run the risk of your account being referred to customer services who may consider suspending your account.

Having said that I hope that you continue to contribute to this site and that your experience proves useful to many others in future.
0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6392549
Try this:

for i = 1 to 10000
  sConnection.Execute "INSERT INTO Table1(field1,field2) VALUES('blah','blah   blah')"
next

'If you want the no. i, to be used to identify the records, you can use it in the field values, here. Note that SQL queries execution is faster than recordsets usage.
0
 

Expert Comment

by:costello
ID: 6394983
Rejecting ibrahim-darahem's answer, and transforming it back to a comment, for above reasons.

dougtimms,
This does not mean this comment is not right, you can still accept it.

costello
Community Support MOderator @ Experts-Exchange
0
 

Expert Comment

by:amp072397
ID: 6770183
dougtimms:

The following is a list of your open questions. You continue to log in to EE, but do not respond.

Please do not give grades less than A without specifically stating why.

Please do not use the delete button, it doesn't work. You must state your intent to delete the question IN the question. After a full three days has passed and no one has objected to deleting the question, you must post a question at community support (CS) at:

http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

You can title the question something like "Please delete this question." Provide a link to the question in the question at CS.

You have never provided feedback:
http://www.experts-exchange.com/jsp/qShow.jsp?ta=oracle&qid=20132247
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20169287
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20258652

You asked for further explanation, then never gave feedback to it:
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20126496

I am sending a copy of my post to the Community Support Administrator; you should hear from him in a day or two. I am also posting in all of your open questions.

thanks in advance for cleaning them up!
amp
community support moderator
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7199985
Hi dougtimms,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept kdg2000's comment(s) as an answer.

dougtimms, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 5

Expert Comment

by:Netminder
ID: 7213387
Per recommendation, force-accepted.

Netminder
CS Moderator
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question