DataTables and Column Conversions

  • Thread starter Thread starter Harry
  • Start date Start date
H

Harry

Hello,
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
column?

Thanks in advance,
- Harry
 
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.
 
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?

Thanks
- Harry
 
Back
Top