Performance: searching and updating

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi. I have profiled my code and discovered where the bottlenecks are:

1. To find unique records I have been using DataTable.Select() but this
appears to be quite slow. What is the fastest method of searching keyed data
for a row with a particular key value?

2. At one point I need to do cell by cell updates to my data. For example if
I have an array of values for a particular column I do this:

for( int rowIndex = 0; rowIndex < myTable.Rows.Count; ++rowIndex )
myTable.Rows[ rowIndex ][ "MyColumn" ] = myArray[ rowIndex ];

Again this is quite expensive. What can I do to speed up this kind of
update? Turn off constraints? Enable some kind of batch update?

Thanks

kh
 
kh said:
Hi. I have profiled my code and discovered where the bottlenecks are:

1. To find unique records I have been using DataTable.Select() but this
appears to be quite slow. What is the fastest method of searching keyed
data
for a row with a particular key value?

DataTable.Rows.Find should do just fine.
2. At one point I need to do cell by cell updates to my data. For example
if
I have an array of values for a particular column I do this:

for( int rowIndex = 0; rowIndex < myTable.Rows.Count; ++rowIndex )
myTable.Rows[ rowIndex ][ "MyColumn" ] = myArray[ rowIndex ];

Again this is quite expensive. What can I do to speed up this kind of
update? Turn off constraints? Enable some kind of batch update?

DataTable.BeginLoadData, EndLoadData.
Perhaps you should also block redrawing of bound control if there is any.
 
Thanks Miha. I'll give them a go

kh


Miha Markic said:
kh said:
Hi. I have profiled my code and discovered where the bottlenecks are:

1. To find unique records I have been using DataTable.Select() but this
appears to be quite slow. What is the fastest method of searching keyed
data
for a row with a particular key value?

DataTable.Rows.Find should do just fine.
2. At one point I need to do cell by cell updates to my data. For example
if
I have an array of values for a particular column I do this:

for( int rowIndex = 0; rowIndex < myTable.Rows.Count; ++rowIndex )
myTable.Rows[ rowIndex ][ "MyColumn" ] = myArray[ rowIndex ];

Again this is quite expensive. What can I do to speed up this kind of
update? Turn off constraints? Enable some kind of batch update?

DataTable.BeginLoadData, EndLoadData.
Perhaps you should also block redrawing of bound control if there is any.
 
Use .Find which is the fastest, but the keys should be the primary key in
the table,

Select is slower.
Actually it depends on the number of rows that you have, as the DataTable is
not strongly types its not the best option, depending on the size of the
application you can choose to go for strongly typed collection. either using
hashtable or hashlist [Have to wite the same]

Anubhav Mishra
 
Back
Top