By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,658 Members | 1,501 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,658 IT Pros & Developers. It's quick & easy.

Adding rows to DataTable

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.