1

How can I do this. I have about 10000 records in an an Excel file and I want to insert all records as fast as possible into an access database?

Any suggestions?

2
  • 5
    Where are the records? In another database, in a data file? What format? Commented Jan 10, 2011 at 12:28
  • Do you mean fast = performant, or fast = easy? Also, +1 on "Where are the records?" Commented Jan 10, 2011 at 13:02

2 Answers 2

1

What you can do is something like this:

    Dim AccessConn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Test Files\db1 XP.mdb") 
    AccessConn.Open() 
    Dim AccessCommand As New System.Data.OleDb.OleDbCommand("SELECT * INTO [ReportFile] FROM [Text;DATABASE=C:\Documents and Settings\...\My Documents\My Database\Text].[ReportFile.txt]", AccessConn) 
    AccessCommand.ExecuteNonQuery() 
    AccessConn.Close() 

Switch off the indexing on the affected tables before starting the load and then rebuilding the indexes from scratch after the bulk load has finished. Rebuilding the indexes from scratch is faster than trying to keep them up to date while loading large amount of data into a table.

If you choose to insert row by row, then maybe want to you consider using transactions. Like, open transaction, insert 1000 records, commit transaction. This should work fine.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi What is this code on the 3rd line - the ReportFile and the [Text;Database=XXX]
@Ilyas Have a look at connection strings, the above is for text, you can also use Excel strings: connectionstrings.com/excel
Why drop indexes for just 10K records? That's peanuts. And when you put them back on, it's going to have to populate them, anyway, so you really haven't gained all that much. And, frankly, I'd rather have data rejected if it violates the indexes, than have re-creating the indexes fail because the data violates one or more of them.
0

Use the default data import features in Access. If that does not suit your needs and you want to use C#, use standard ADO.NET and simply write record-for-record. 10K records should not take too long.

3 Comments

There is no difficulty in writing an sql statement to run against a connection that will insert all records at once, unless they are in some pretty obscure format.
Record for record takes too long and isnt acceptable for me. The records are in an excel file.
If you know up front your source is an Excel file, it helps if you put that in the question. This stops people from guessing your scenario. Since you tagged your question with C#, I am assuming you want to do this from code, right?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.