What’s the best way to bulk database inserts from c#?

前端 未结 10 2165
盖世英雄少女心
盖世英雄少女心 2020-12-02 14:22

How do I/what’s the best way to do bulk database inserts?

In C#, I am iterating over a collection and calling an insert stored procedure for each item in the collect

10条回答
  •  孤城傲影
    2020-12-02 14:58

    Create a XML document that contains all the items to be inserted. Then inside of a stored procedure, use the TSQL xml support (OPENXML) to read all the data from the XML document and insert it into your tables with hopefully one insert statement for each table.

    However if you are only inserting data into a single table and don’t need any database side logic, why not use SqlBulkCopy?

提交回复
热议问题