473,487 Members | 2,601 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

DataTable.Select performance

Luc
I am using Visual Studio 2003 and am getting lousy performance after using
a datatable select and then trying to assign a value to a column of the row
that was found:

DataTable dt = new DataTable();
dt.Columns.Add("Number", System.Type.GetType("System.Int32"));
dt.Columns.Add("Value", System.Type.GetType("System.Double"));

for(int i=0;i<2000;i++)
{
DataRow dr = dt.NewRow();
dr["Number"] = i;
dr["Value"] = 1.0;
dt.Rows.Add(dr);
}

for(int i=0;i<2000;i++)
{
// use the select
string filter = "Number = " + i;
DataRow[] rows = dt.Select(filter);

// assign a new value to the row that was found
if(rows.Length > 0) rows[0]["Value"] = 2;
}

I want to note that this is only if both a select and assign are used
together. Performance is fine if one is used without the other. Anyone
encounter this and know of a workaround?
Jul 21 '05 #1
1 8079
Luc,
I want to note that this is only if both a select and assign are used
together. Performance is fine if one is used without the other. Anyone
encounter this and know of a workaround?
I would expect updating a value in a DataTable to take a certain amount of
time. As the previous values need to be saved & the new values set. Remember
that a DataRow actually contains upto 4 versions of the row based on the
DataRowVersion enum.

Interesting enough, if you define a primary key on the Number column (the
column you are selecting on) then the select & update goes about as fast as
just Select. As defining an "index" (Primary Key or DataView) on a column
will make Select go faster, as Select will use this "index".
dt.Columns.Add("Number", System.Type.GetType("System.Int32"));
dt.PrimaryKey = new DataColumn[] {dt.Columns[Number]}

Alternatively you can use a DataView & FindRows if the column you are
selecting on is not the primary key column.

Hope this helps
Jay

"Luc" <Lu*@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...I am using Visual Studio 2003 and am getting lousy performance after using
a datatable select and then trying to assign a value to a column of the
row
that was found:

DataTable dt = new DataTable();
dt.Columns.Add("Number", System.Type.GetType("System.Int32"));
dt.Columns.Add("Value", System.Type.GetType("System.Double"));

for(int i=0;i<2000;i++)
{
DataRow dr = dt.NewRow();
dr["Number"] = i;
dr["Value"] = 1.0;
dt.Rows.Add(dr);
}

for(int i=0;i<2000;i++)
{
// use the select
string filter = "Number = " + i;
DataRow[] rows = dt.Select(filter);

// assign a new value to the row that was found
if(rows.Length > 0) rows[0]["Value"] = 2;
}

I want to note that this is only if both a select and assign are used
together. Performance is fine if one is used without the other. Anyone
encounter this and know of a workaround?

Jul 21 '05 #2

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

Similar topics

3
2108
by: nandan | last post by:
Hi, Has any one ever compared the performance of calling a DataTable's Select method with a stored procedure doing the same thing? My point is: dataRows = DataTable.Select(filter) is better or...
4
2543
by: Kris Rudin | last post by:
I am displaying a table of information on a web page, using an asp:table that I populate dynamically. On this page I give the user the options to group the rows by certain fields, and/or filter the...
1
424
by: Luc | last post by:
I am using Visual Studio 2003 and am getting lousy performance after using a datatable select and then trying to assign a value to a column of the row that was found: DataTable dt = new...
7
14974
by: wk6pack | last post by:
Hi, How do I check datatable.select(filter) in the following: for each dtrow in datatable.select(filter) .... next I've also tried:
4
7100
by: Aryan | last post by:
Hi, I am having problem with DataTable.Select() method. I am using ASP.NET 2.0. I have DataSet which reads data from XML file using DataSet.ReadXML(). Now this dataset has various datatable,...
2
4376
by: Larry Smith | last post by:
Hi there, Can anyone comment on the performance issues of "DataTable.Select()" vs "DataView.Find()" (or "DataView.FindRows()"). I have to conduct repeated searches using the same index and I'm...
1
29933
by: Dave | last post by:
Hello, What is the best way (performance wise) to search for a row in a table? Let say I have a column named "col1" and what to get the row that the value of "col1" is "It is me"... I can set...
2
2252
by: Mukesh | last post by:
Hi all I am developing a webportal on VS2005 and ASP.NET 2.0 Using MsSQL SERVER 2005. I have some static records(around 15000) in the database.These contents never changed while the...
1
4787
by: Cappamontana | last post by:
Hi, I have a question for those who have some experience with select LIKE statements on huge data (about 200 million rows). When I run some computing and filtering on this table, it takes the...
0
7106
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
6967
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
7181
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
7349
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
5442
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,...
1
4874
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3076
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...
1
600
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
267
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.