473,491 Members | 3,350 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Datatable updates taking too long...

VM
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?
Nov 16 '05 #1
3 2605
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
Nov 16 '05 #2
VM
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

Nov 16 '05 #3
VM <vo******@yahoo.com> wrote:
Do you mean that after I modify the table, the Select will take longer ?
Yes. There's a thread about it at the moment in the .adonet group.
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?
That probably wouldn't be terribly easy, although I'm sure it would be
doable. It shouldn't take up much memory to build up an ArrayList of
DataRows references though.
And you're right about the foreach, but I'm still having trouble
understanding it...


In this case it would be:

foreach (DataRow row in table_rowNums.Rows)
{
....
}

I would seriously think about abandoning ADO.NET until you've got the
basics of C# down thoroughly though - it'll make it much easier to get
to grips with ADO.NET itself.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2926
by: VM | last post by:
When I display data to a Windows datagrid I usually fill the underlying table (in another class) and then, once it contains all the data, I attach it to the grid. But there are some processes that...
4
960
by: Mike Labosh | last post by:
I have this giant table in our database that represents a dumping ground for file imports. It's 44 columns wide and nominally about 30 million records, indexed in blocks by the file the records...
5
3166
by: Ron L | last post by:
I have a DataTable that is being maintained in a Model class. I also have a View class which creates a DataView from the DataTable that the Model passes it. The view class then has methods to...
1
9156
by: j.zascinski | last post by:
Hi, i have a "simple" problem with gridview, please help me :) i want to have gridview which is binded to a datatable (or a dataset). i can show the data from the dataset in the gridview and i can...
1
3439
by: Tim Cowan | last post by:
Hi, I was wondering if there is a quicker way to do this? I have a select all check box for data in a grid and when checked I want the checkboxes in the grid to be checked. I am currently...
2
4047
by: RSH | last post by:
Hi, I have a situation where I am querying SQL Server and bringing back a Dataset. Is there a way to dump the datatable to a delimited text file without iteration through the datatable? The...
15
13471
by: Joseph Geretz | last post by:
I'm a bit puzzled by the current recommendation not to send Datasets or Datatables between application tiers. http://support.microsoft.com/kb/306134 ...
5
1990
by: jehugaleahsa | last post by:
Hello: I am trying to find what is the very best approach to business objects in Windows Forms. Windows Forms presents an awesome opportunity to use DataTables and I would like to continue doing...
5
5875
by: jehugaleahsa | last post by:
Hello: What is the point of using a DataTable in ASP .NET? We are unsure how you can use them without 1) rebuilding them every postback, or 2) taking up precious memory. We are not sure how to...
0
7118
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6980
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7192
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7364
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5452
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3087
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.