472,953 Members | 1,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 7974
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
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
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
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
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
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
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
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
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
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
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.