473,320 Members | 1,879 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,320 software developers and data experts.

Adding rows to DataTable

Hi, All!
I have the following code:
DataRow newDataRow;
for (int i = 1; i <= count; i++)
{
newDataRow = table.NewRow();
newDataRow["FLD_START_TIME"] = interval.start;
newDataRow["FLD_END_TIME"] = interval.finish;
newDataRow["VALUE"] = metricData.val;
newDataRow["METRIC_APP"] = metricData.appValue;
newDataRow["METRIC_MAX"] = metricData.maxValue;
newDataRow["METRIC_MIN"] = metricData.minValue;
newDataRow["METRIC_STATUS"] = metricData.metricStatus;
table.Rows.Add(newDataRow);
}

As you can see it adds "count" records into DataTable. But when the
"count" is big (100 or more) it takes some seconds to add this rows. How can
I decrease performance time of this operation?

Thanks a lot
Nov 17 '05 #1
3 30549
Aleksey,

There really isn't any way around it, from what I can tell. This is the
most efficient way to add rows (there are only two overloads for the Add
method, and neither will allow bulk operations).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Aleksey" <al************@il.quest.com> wrote in message
news:e5**************@TK2MSFTNGP15.phx.gbl...
Hi, All!
I have the following code:
DataRow newDataRow;
for (int i = 1; i <= count; i++)
{
newDataRow = table.NewRow();
newDataRow["FLD_START_TIME"] = interval.start;
newDataRow["FLD_END_TIME"] = interval.finish;
newDataRow["VALUE"] = metricData.val;
newDataRow["METRIC_APP"] = metricData.appValue;
newDataRow["METRIC_MAX"] = metricData.maxValue;
newDataRow["METRIC_MIN"] = metricData.minValue;
newDataRow["METRIC_STATUS"] = metricData.metricStatus;
table.Rows.Add(newDataRow);
}

As you can see it adds "count" records into DataTable. But when the
"count" is big (100 or more) it takes some seconds to add this rows. How
can
I decrease performance time of this operation?

Thanks a lot

Nov 17 '05 #2
Hi,

There is nothing much you can do, just a little optimization:
Use indices for columns instead of name, this save a lookup

other than that I can think of nothing at all :(
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


"Aleksey" <al************@il.quest.com> wrote in message
news:e5**************@TK2MSFTNGP15.phx.gbl...
Hi, All!
I have the following code:
DataRow newDataRow;
for (int i = 1; i <= count; i++)
{
newDataRow = table.NewRow();
newDataRow["FLD_START_TIME"] = interval.start;
newDataRow["FLD_END_TIME"] = interval.finish;
newDataRow["VALUE"] = metricData.val;
newDataRow["METRIC_APP"] = metricData.appValue;
newDataRow["METRIC_MAX"] = metricData.maxValue;
newDataRow["METRIC_MIN"] = metricData.minValue;
newDataRow["METRIC_STATUS"] = metricData.metricStatus;
table.Rows.Add(newDataRow);
}

As you can see it adds "count" records into DataTable. But when the
"count" is big (100 or more) it takes some seconds to add this rows. How
can
I decrease performance time of this operation?

Thanks a lot

Nov 17 '05 #3
One thing that you might want to try is

table.Rows.Add(new object[] { interval.start, interval.finish,
metricData.val, metricData.appValue, metricData.maxValue,
metricData.minValue, metricData.metricStatus });

It will save you from having to create a new DataRow object on every
iteration. Might give you a little bit of a performance boost.

HTH,
Bill Priess, MCP

"Aleksey" <al************@il.quest.com> wrote in message
news:e5**************@TK2MSFTNGP15.phx.gbl...
Hi, All!
I have the following code:
DataRow newDataRow;
for (int i = 1; i <= count; i++)
{
newDataRow = table.NewRow();
newDataRow["FLD_START_TIME"] = interval.start;
newDataRow["FLD_END_TIME"] = interval.finish;
newDataRow["VALUE"] = metricData.val;
newDataRow["METRIC_APP"] = metricData.appValue;
newDataRow["METRIC_MAX"] = metricData.maxValue;
newDataRow["METRIC_MIN"] = metricData.minValue;
newDataRow["METRIC_STATUS"] = metricData.metricStatus;
table.Rows.Add(newDataRow);
}

As you can see it adds "count" records into DataTable. But when the
"count" is big (100 or more) it takes some seconds to add this rows. How
can
I decrease performance time of this operation?

Thanks a lot

Nov 17 '05 #4

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

Similar topics

4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
2
by: a | last post by:
I get the error that "Argument"1": cannot convert from 'string' to 'System.Data.DataRow' at the foreach loop to add rows to the DataTable...any ideas how to fix this? Paul ...
3
by: Robin Thomas | last post by:
I am fairly new to ASP.NET so I think I am missing something fundamental. Anyway, quite often I am pulling data from a database, but then I need to use that data to produce more data. A simple...
1
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple...
1
by: psb | last post by:
I thought this was weird?? is this a bug in framework 1.0??? (1.0 is the version I am running against) --------------------------- dim dtAll as new datatable dim dtTmp as datatable dtTmp =...
2
by: Niels Jensen | last post by:
I have the following code in a Sub which is called by a do loop statement for each line starting with unit info in an e-mail based game that I play. I'm exctracting the keywords from the text and...
2
by: Flack | last post by:
Hey guys, I have a DataGrid and DataTable field in my class : private ImageDataGrid dataGrid1; //ImageDataGrid extends dataGrid and just overides OnMouseDown private DataTable dt = new...
6
by: Paulers | last post by:
Hello, I have a string that I am trying to add each char to a datatable row. for example if I have a string that looks like "abcdefg", I would like to break it up into an array of characters...
2
by: canoewhiteh2o | last post by:
I am having trouble adding data columns to a disconnected database. I first load a datatable using: private DataTable dtMacros = new DataTable(); private ArrayList macro = new ArrayList();...
8
by: jehugaleahsa | last post by:
Hello: We wrote an entire application where we add our DataRows to our DataTables immediately. However, we have to shut off our constraints to do this. We would like to use detached DataRows to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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)...
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.