DataTables and Column Conversions

DataTables and Column Conversions

Post by robinso » Sat, 06 Dec 2003 06:41:20

I'm calling the DataTable.Compute(string expression, string filter)
public method to perform simple mean, min, max, etc. computations.
However the data stored in this table, let say people's ages, is of
type nvarchar/string and I need these computations to be performed as
if their type was integer this way the aggregate functions perform the
computations numerically and not lexically. Further, I can't change
the database schema so I have to deal with the conflicting types. The
obvious solution is to convert the column that holds this age data
from nvarchar to Int32, but how do I go about doing this from within
the DataTable.Compute method? Is this even possible or do I have to
create a new column in the table of type Int32 and set it's expression
to the value of this data column I'm interested in and wrap it in a
Convert function and then call the aggregate functions on this new

Thanks in advance,
- Harry

DataTables and Column Conversions

Post by Miha Marki » Sat, 06 Dec 2003 07:00:53

Hi Harry,

Compute should understand Convert function:

Convert(expression, type)
expression-- The expression to convert.
type-- The .NET Framework type to which the value will be converted.

excerpt from .net help files.

Miha Markic - RightHand .NET consulting & development
miha at rthand com


DataTables and Column Conversions

Post by Harry Robi » Sat, 06 Dec 2003 07:23:40

Hi Miha,
I have tried to pass the Convert function in both the expression and
filter parameters of the compute method, however, this only results in
an Exception being thrown. Could you provid an example of how to use the
Convert function inconjunction with the compute method?

- Harry

*** Sent via Developersdex ***
Don't just participate in USENET...get rewarded for it!