datarow updates: slow?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi all,

my code currently reads as the following:

//////

double tmpposition = (double)dr["position"] + pos;

dr["position"] = tmpposition;

//////



where dr is a DataRow and pos is of type double. however it seems that the
second line takes quite a while to execute - around a quarter of a second.
however, adding new rows to the table in which the row resides is quick, as
is selecting etc.

am i updating the row value incorrectly?



tia!

spammy
 
Hi Spammy,

Is your row bound to some UI control perhaps?
Are there any other factors involved?
Normally it should be a breeze...
 
Miha,

its a command line app, so no UI controls. ive tried to make the code as
brief as possible for simplicity, but obviously that may have hidden the
problem too.

more code:

DataRow[] targets = result.Select("ColA = '" + ColA + "' AND ColB = '" +
ColB + "' AND ColC = '" + ColC + "' AND ColD = '" + ColD+ "'");

if (targets.Length == 0)

{

//none exist - set up row

string secname = getSecName(secid, prices);

result.Rows.Add(new object[] {ColA, ColB, ColC, ColD, name, pos, p,
change});

}

else if (targets.Length == 1)

{

//amend exisitng

double tmpposition = (double)targets[0]["position"] + pos;

targets[0]["position"] = tmpposition;

}

else

{

throw new Exception("Too many entries found in table!!");

}


Miha Markic said:
Hi Spammy,

Is your row bound to some UI control perhaps?
Are there any other factors involved?
Normally it should be a breeze...

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

spammy said:
hi all,

my code currently reads as the following:

//////

double tmpposition = (double)dr["position"] + pos;

dr["position"] = tmpposition;

//////



where dr is a DataRow and pos is of type double. however it seems that the
second line takes quite a while to execute - around a quarter of a second.
however, adding new rows to the table in which the row resides is quick, as
is selecting etc.

am i updating the row value incorrectly?



tia!

spammy
 
Hi,

Try executing the problematic code in a loop so you'll eliminate the "first
hit" issue.
If you don't have a profiler handy, place a timing code before and after,
i.e.
DateTime start = DateTime.Now;
.....
TimeSpan elapsed = DateTime.Now-start;

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

spammy said:
Miha,

its a command line app, so no UI controls. ive tried to make the code as
brief as possible for simplicity, but obviously that may have hidden the
problem too.

more code:

DataRow[] targets = result.Select("ColA = '" + ColA + "' AND ColB = '" +
ColB + "' AND ColC = '" + ColC + "' AND ColD = '" + ColD+ "'");

if (targets.Length == 0)

{

//none exist - set up row

string secname = getSecName(secid, prices);

result.Rows.Add(new object[] {ColA, ColB, ColC, ColD, name, pos, p,
change});

}

else if (targets.Length == 1)

{

//amend exisitng

double tmpposition = (double)targets[0]["position"] + pos;

targets[0]["position"] = tmpposition;

}

else

{

throw new Exception("Too many entries found in table!!");

}


Miha Markic said:
Hi Spammy,

Is your row bound to some UI control perhaps?
Are there any other factors involved?
Normally it should be a breeze...

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

spammy said:
hi all,

my code currently reads as the following:

//////

double tmpposition = (double)dr["position"] + pos;

dr["position"] = tmpposition;

//////



where dr is a DataRow and pos is of type double. however it seems that the
second line takes quite a while to execute - around a quarter of a second.
however, adding new rows to the table in which the row resides is
quick,
as
is selecting etc.

am i updating the row value incorrectly?



tia!

spammy
 
Back
Top