473,326 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

foreach Vs. dt.Select

Ben
Hi all,

I need to update an particular set of rows in a datatable.
Here is some sample code of what I want to do:

DataTable dt = (DataTable)Session["Table"];
foreach(DataRow dr in dt.Rows)
{
if(dr.RowState == DataRowState.Added)
//Do something
}

Instead, I could also do:
DataRow[] dr = dt.Select("","",DataViewRowState.Added);
if(dr.Length 0)
{
for(int i = 0; i < dr.Length; i++)
{
DataRow drCurrent = dr[i];
//Do Something
}
}
My question is: Is there a significant performance difference between
the two approaches? The datatable should only have a few records
(maximum 10).

Thanks in advance,
Ben
*** Sent via Developersdex http://www.developersdex.com ***
Mar 6 '08 #1
1 2366
For sure is the select slower, the select uses an expression which has first
to be translated.

The enumurating through the property rows is for sure as fast as the doing
the same through the collection of rows (although it are probably less
rows). As Peter already wrote, you have to investigate the result of the
select first because it can return null. And then you loose even more time.

We are talking probably about thousands of picoseconds

Cor

Mar 12 '08 #2

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

Similar topics

0
by: Randell D. | last post by:
Folks, Ever since reading an interesting article in Linux Format on PHP whereby suggested code writing was made that could enhance performance on a server, I've started testing various bits of...
4
by: Marco | last post by:
Hi there ive trying to make a game based on php and currently ive some problems with this part of the script, i've tryed to fix it alone with out success... This is the script <?php...
5
by: Gustavo Randich | last post by:
Hello, I'm writing an automatic SQL parser and translator from Informix to DB2. Now I'm faced with one of the most difficult things to translate, the "foreach execute procedure" functionality...
9
by: Anthony Bouch | last post by:
Everything I know about looping structures says to be careful about expressions that need to be evaluated again and again for each test/increment of a loop. I came across this piece of code the...
7
by: david | last post by:
I need 5 queries from the database, which I display in a php foreach loop the following way. $query1 = $DB->query("SELECT ... DESC LIMIT 20"); $query2 = $DB->query("SELECT ... DESC LIMIT 20");...
4
by: atyndall | last post by:
OK, this is the relevant portion script: <?php $username = '__'; // MySQL Database Username. $password = '__'; // MySQL Database Password. $server = '__'; // MySQL Database server (most...
3
dcharnigo
by: dcharnigo | last post by:
I am writing a purge routine for a database that I have. I select all records that have aged to a certain threshold into a temp table, now I want to remove some of these items, then in the end after...
14
by: rashgang | last post by:
i have dynamically created checkbox which will like yahoo mail if check box selected it will highlight a row but deleteall function is not working plz chek it function doDeleteAll($objArray){ ...
21
by: rashgang | last post by:
no check box selected when i gave delete all link the error is coming <?php include "includes/connection.php"; include "includes/Functions_category.php"; include...
4
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.