I´ve to do several inserts into one table. Now, I´ve a list of objects that i iterate, and for each object i do an ExecuteNonQuery with the insert statement.
I want to know if there are a faste way to do this.
In this way, inserting 800 registers takes a couple of minutes.
I´ve used in Java the executeBatch method, who is for this propose, is there anything similar in c#.
Regards !
Inserts are [relatively] fast/cheap. Commits are slow/expensive.
Unless it is a high latency connection, multiple (as in, hundreds of) insert statements should be just fine.
“…takes a couple minutes…” sounds like transactions are not being used (and thus there are likely 800 commits — ouch!). One of the easiest ways to control transactions in C# is to use a TransactionScope:
I would only consider approaches if limiting the number of transactions (and thus commits) is not sufficient to meet functional requirements.
Happy coding.