Re: Problem with Expression Column



My following piece of code draws on Northwind sample database, in particular
tables Orders and OrderDetails.

Having added DataTables based on Orders and OrderDetails to a DataSet, I
then added the relation "FK_OrderDetails_Orders" to the dataset relating the
two tables. Now I wish to add an expression column (namely OrderAmount) to
Orders datatable showing for each Orders row, sum total of the products
"OrderDetails.UnitPrice * OrderDetails.Quantity" for related child rows in
OrderDetails.

I tried following aggregate expression that seems a correct natural
expression for the logic but code fails with run time error
"SyntaxErrorException". Details of the error are also appended below the
code.

//Code starts here
DataColumn expressionColumn;

expressionColumn = new DataColumn("OrderAmount",
Type.GetType("System.Decimal"), "SUM(Child(FK_OrderDetails_Orders).UnitPrice
* Child(FK_OrderDetails_Orders).Quantity)");

NWindDataSet.Tables["Orders"].Columns.Add(expressionColumn);

Details of exception
SyntaxErrorException was unhandled
Syntax error in aggregate argument; expecting a single column argument with
possible 'Child' qualifier.

I did manage a workaround by first adding an expression colum to the
OrderDetails table (ItemAmount = UnitPrice*Quantity) and then taking the
aggregate of this child expression colum in the parent expression column.

I find msdn help quite vague on expression usage. The error suggests of a
single column limit but is equally vague. Can anyone please find out problem
with my expression code or explain this error more precisely.

Thanks
Mansoor


.



Relevant Pages

  • RE: Fill a joined typed dataset
    ... I would like to confirm my understanding of your issue. ... we cannot use this stored procedure to fill the ... you can add an expression column in ... the OrderDetails table to achieve this. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Problem with Expression Column
    ... Having added DataTables based on Orders and OrderDetails to a DataSet, ... "SyntaxErrorException". ... aggregate of this child expression colum in the parent expression column. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Filter Master Table based on Child Criteria
    ... records depend on the parent and the datarelation forces the filtering. ... DataRelation and from a child DataView. ... OrderDetails = Child) ... If we populate each of the DataTables with ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Filter Master Table based on Child Criteria
    ... DataRelation and from a child DataView. ... OrderDetails = Child) ... If we populate each of the DataTables with ... I need to access all of the Orders records associated with these 10 ...
    (microsoft.public.dotnet.framework.adonet)
  • Filter Master Table based on Child Criteria
    ... DataRelation and from a child DataView. ... OrderDetails = Child) ... If we populate each of the DataTables with ... I need to access all of the Orders records associated with these 10 ...
    (microsoft.public.dotnet.framework.adonet)