Monday, March 26, 2012

Performing Arithmetic on DataTable Columns

I have a DataTable with only one DataColumn of type float. I need to
calculate the Max value that in any of the DataRows, and this DataColumn.
I noticed the DataColumn has an Expression property:
http://msdn.microsoft.com/library/d...essionTopic.asp
However, it seems that I would end up having to create a new DataColumn,
call it MaxVal or something, and populate it for every row.
Is there a cleaner way?Nevermind, I discovered the Compute method.
float flMax =
(float)m_dsSegments.Tables["Calculations"].Compute("Max(Score)",
string.Empty);
"George Durzi" <gdurzi@.hotmail.com> wrote in message
news:O30tjLLTEHA.240@.TK2MSFTNGP11.phx.gbl...
> I have a DataTable with only one DataColumn of type float. I need to
> calculate the Max value that in any of the DataRows, and this DataColumn.
> I noticed the DataColumn has an Expression property:
>
http://msdn.microsoft.com/library/d...essionTopic.asp
> However, it seems that I would end up having to create a new DataColumn,
> call it MaxVal or something, and populate it for every row.
> Is there a cleaner way?
>
If your contents are bound to a dataset why don't you just use the dataset
ds.Tables[0].Compute("Max(["+strColumnName+"])",String.Empty)
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"George Durzi" <gdurzi@.hotmail.com> wrote in message
news:O30tjLLTEHA.240@.TK2MSFTNGP11.phx.gbl...
>I have a DataTable with only one DataColumn of type float. I need to
> calculate the Max value that in any of the DataRows, and this DataColumn.
> I noticed the DataColumn has an Expression property:
> http://msdn.microsoft.com/library/d...opi
c.asp
> However, it seems that I would end up having to create a new DataColumn,
> call it MaxVal or something, and populate it for every row.
> Is there a cleaner way?
>

0 comments:

Post a Comment