Hi I have a Populated Generic List in a winform and now wanna to send its data into a SQL server table as a bulk Copy. As I read the SqlBulkCopy Class, it needs a data reader as a source.
Now, how can I convert it to a DataReader?
You can convert it to DataTable and send to SqlBulkCopy. It would be much easier, and there is no performance penalty, because all data is already present in memory.
There is similar question on SO.
If the data-volume is sane enough to exist as a
List<T>, you might as well just construct a
DataTable and push the data in that way. I don't like
DataTable, but it does this job nicely. The alternative would be to write a custom
IDataReader implementation like this, but which iterates over the items in the list each time. I'm not sure it is worth the effort.