How can i speed up time while inserting multiple data?
I get data from excel and I store them in List. In my loop, I open connection for every row and then I close with my Insert function. Insert function insert data row by row. Sometimes this operation takes a lot of time. My insert loop like this
private void btnSave_Click(object sender, RoutedEventArgs e)
{
if (cmpList.Count == 0)
{
MessageBoxHelper.ShowError("List can not be inserted");
return;
}
foreach (var item in cmpList)
{
item.StartDate = dpStart.SelectedDate.Value;
item.FinishDate = dpFinish.SelectedDate.Value;
item.Insert();
}
MessageBoxHelper.ShowInformation("List was inserted successfully!");
comboCampaignType.IsEnabled = true;
}
I create cmpList for all row from excel like this
for (int i=0; i<excelRowCount; i++)
{
Campaign cmp = new Campaign();
cmp.Type = 1;
cmp.PriceP.Amount = double.Parse((string)sheet.GetRow(row).GetCell(1).Value, CultureInfo.InvariantCulture);
cmp.PriceV.Amount = double.Parse((string)sheet.GetRow(row).GetCell(1).Value, CultureInfo.InvariantCulture);
cmp.PriceP.Currency = (string)sheet.GetRow(row).GetCell(2).Value;
cmp.PriceV.Currency = (string)sheet.GetRow(row).GetCell(2).Value;
cmp.MinOrder = Convert.ToDouble((string)sheet.GetRow(row).GetCell(3).Value);
cmpList.Add(cmp);
}
So, is there any way to insert list at once? Any ideas how to speed up this operation ?