Kuba Matjanowski
Kuba Matjanowski

Reputation: 350

Bulk insert Datatable to MSAccess (MSExcel) database (C#)

I need to insert to the Microsoft Access Database (accdb file) large amount of data (about 500MB per table).
My soft downloads table A from the net and I have an DataTable object with data from table A. Inserting data row by row using OleDbCommand (ADO.NET provider) takes to much time. What is more, the more records are in the database, the more time inserting takes.

Is there any alternative to insert data faster (all the datatable per command)? Destination database could has rows before inserting my rows.

Regards, Jakob.

Upvotes: 2

Views: 2971

Answers (1)

Rohit
Rohit

Reputation: 10236

Try this to perform bulk insert . More Info :INSERT INTO Statement (Microsoft Access SQL)

var cmdText = "INSERT INTO Table1 SELECT * FROM Table2";
var command = new OleDbCommand(cmdText, connection);
command.ExecuteNonQuery();

Or you can take a look at This article

Note: The above code perform bulk insert from one accdb to another accdb .However there is no bulk insert method from Dataset to Access DB, you would have to insert the data row by row.

Upvotes: 1

Related Questions