Do you mean that after I modify the table, the Select will take longer ?
Because if I comment the line that modifies the row, it all takes less than
4 secs.
Regarding your suggestion, I already have a table (an exact copy of the
original) that only includes all the records that are going to be modified.
Once I modifiy this temp table, how can I update the original table with the
rows in the temp table?
And you're right about the foreach, but I'm still having trouble
understanding it...
Thanks,
VM
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP***********************@msnews.microsoft.co m...
VM <vo******@yahoo.com> wrote: Why is the third line of code in the loop take so long? W/o that line,
the execution (35,000 loops) runs in 3 secs. With the line, it goes up to
over 5 mins.
dataGrid_auditAddress.DataSource = null;
for(int i=0;i<table_rowNums.Rows.Count; i++)
{
iRowNum = Convert.ToInt32(table_rowNums.Rows[i]["col_rowNums"]);
//this table has all row numbers that will be modified
DataRow[] row_1 = DT_tempTable.Select("col_row = " +
iRowNum.ToString());
row_1[0]["col_mark"] = MARKED; //line that takes too long
}
dataGrid_auditAddress.DataSource = DT_tempTable;
Is there a better way of doing it?
I don't believe it's the third line which is taking that long - I
believe it's that having changed the contents of the table, the Select
takes a long time. I suggest you change to (say) building up an
ArrayList of all the rows you want to change, then changing them all in
one go.
(I'd also start using foreach for readability, btw.)
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too