I need to improve dramatically the execution time of a process wich currently is just like this:
private Dictionary<int, SingleElement> elements_buffer;
// ... Create and load values into "elements_buffer"
// (string, Datetime, double)
string query = "INSERT INTO Tests.dbo.test_table "
+ "(element_name,element_init,element_width) VALUES";
SingleElement element_aux;
for (int i = 0; i < MAX_ELEMS_IN_DICT; i++)
{
element_aux = elements_buffer[i];
query = query
+ "('"
+ element_aux.name
+ "','"
+ element_aux.init
+ "',"
+ element_aux.width
+ ")";
if (i < MAX_ELEMS_IN_DICT+1) {
query = query + ",";
}
}
// ... Execute the query
I was going to use Datatable
for the new version, but I've been reading about using SqlBulkCopy
together with IDatareader
, as mentioned in:
It looks like to me a better choice for my code, but can't get to figure it out how to code it, though I would like to use it.
Can I have some help with the translated code, please?
Thanks in advance