I have to parse a big XML file and import (insert/update) its data into various tables with foreign key constraints.
So my first thought was: I create a list of SQL insert/update statements and execute them all at once by using SqlCommand.ExecuteNonQuery()
.
Another method I found was shown by AMissico: Method where I would execute the sql commands one by one. No one complained, so I think its also a viable practice.
Then I found out about SqlBulkCopy
, but it seems that I would have to create a DataTable with the data I want to upload. So, SqlBulkCopy
for every table. For this I could create a DataSet.
I think every option supports SqlTransaction
. It's approximately 100 - 20000 records per table.
Which option would you prefer and why?