Quantcast
Channel: How should I multiple insert multiple records? - Stack Overflow
Viewing all articles
Browse latest Browse all 12

Answer by 0014 for How should I multiple insert multiple records?

$
0
0

You can directly insert a DataTable if it is created correctly.

First make sure that the access table columns have the same column names and similar types. Then you can use this function which I believe is very fast and elegant.

public void AccessBulkCopy(DataTable table){    foreach (DataRow r in table.Rows)        r.SetAdded();    var myAdapter = new OleDbDataAdapter("SELECT * FROM "+ table.TableName, _myAccessConn);    var cbr = new OleDbCommandBuilder(myAdapter);    cbr.QuotePrefix = "[";    cbr.QuoteSuffix = "]";    cbr.GetInsertCommand(true);    myAdapter.Update(table);}

Viewing all articles
Browse latest Browse all 12

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>