PC Review


Reply
Thread Tools Rate Thread

datarow updates: slow?

 
 
spammy
Guest
Posts: n/a
 
      13th May 2004
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


 
Reply With Quote
 
 
 
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      13th May 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
spammy
Guest
Posts: n/a
 
      13th May 2004
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 [MVP C#]" <miha at rthand com> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
> >
> >

>
>




 
Reply With Quote
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      14th May 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 [MVP C#]" <miha at rthand com> wrote in message
> news:(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > 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
> > >
> > >

> >
> >

>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Distinguish 2 situations when a DataRow in Detached state; Or why not make the data row intact after being added then removed from a dataRow collection? Ryan Liu Microsoft Dot NET 0 7th Jun 2006 03:04 PM
Distinguish 2 situations when a DataRow in Detached state; Or why not make the data row intact after being added then removed from a dataRow collection? Ryan Liu Microsoft C# .NET 0 7th Jun 2006 02:14 AM
Slow loading DataRow ItemArray Mark Microsoft ADO .NET 2 1st Jul 2005 07:00 PM
datarow updates not showing in datatable =?Utf-8?B?QmV0aA==?= Microsoft Dot NET Compact Framework 2 2nd Mar 2005 05:05 PM
create new DataRow, init fields, then set DataRow to UnChanged? Les Caudle Microsoft ADO .NET 2 4th May 2004 05:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:54 AM.