优化DataTable数据加载

时间:2014-08-18 21:42:06

标签: c# datatable

我正在尝试将数据加载到datatable中。目前,对于加载14000行和3列,需要2分钟。我想优化这个。

sortedDates大小为14K行。

this.TimeSeriesDataTable.BeginLoadData();
foreach (var date in sortedDates)
{
    DataRow newRow = this.TimeSeriesDataTable.NewRow();

    newRow["Dates"] = DateTime.ParseExact(date.ToString(), "yyyyMMdd", CultureInfo.InvariantCulture);

    // Each Series represent columns. No of cols is based on user selection.        
    foreach (TimeSeries sr in series) 
    {
        // I am getting JSON structure with sep array of Dates/Values. 
        // I am creating this dic by zipping the 2 list. 
        Dictionary<int, double> DateValuesMap = sr.DatesValuesDic; 
        double val;
        double seriesValue = DateValuesMap.TryGetValue(date, out val) ? val :  Constants.NAValue;
        if (!isNA(seriesValue)) newRow[sr.Label] = seriesValue;
        else newRow[sr.Label] = Constants.NAValue;
        newRow[sr.Label] = seriesValue;
    }
    this.TimeSeriesDataTable.Rows.Add(newRow);
}
this.TimeSeriesDataTable.EndLoadData();

如何优化此功能?有没有更好的方法来做到这一点?我根本不应该使用DataTable吗?

0 个答案:

没有答案