tags:

views:

10

answers:

1

Hello.

In runtime my app gets data from MSSQL server and there's an object that pulls the data into my custom dataset. Here's the code:

public static void FillRegionData(int country, RegionDataTable DestinationTable)
{
  DestinationTable.Clear();
  using (selectRegionsListTableAdapter _taSource = new selectRegionsListTableAdapter())
  {
    BusStationDataSet.selectRegionsListDataTable _tblSource = _taSource.GetData(country, Settings.Default.DataLanguage);
    foreach (BusStationDataSet.selectRegionsListRow row in _tblSource.Rows)
    {
      DestinationTable.Rows.Add(new object[] { 
        row.region,
        row.country,
        row.title });
    }

  }
}

Everything goes fine until foreach starts working. A bit more than 100 rows causes the whole app to hang for several seconds.

Any ideas why this code is so slow?

A: 

Is DestinationTable perhaps data-bound at this point? Since DataTable issues change notifications, adding lots of data while bound will cause a performance bottleneck. In many cases you can simply suspend the data-binding while you do this. Or alternatively, populate it first, and then give it to the data-binding.

(the difference here is whether it redraws and refreshes the UI once per row, or once overall)

Marc Gravell
DestinationTable is the data source for databinding. I have combobox items bound to it.
7kun
Thanks for the help. After some googling I firgured that it would be more efficient if I'd used diffirenet dataset for each datasource.
7kun