Windows Develop Bookmark and Share   
 index > Windows Forms General > ADO - aggregate functions
 

ADO - aggregate functions

Can someone please confirm my understanding of this code snippet?

dtParent.Columns.Add("P5Sum", GetType(Decimal), "Sum(Child(GroupBy2Summary).P5)")


This code snippet should add a column to the parent table named P5Sum, which will contain the result of the sum of all rows of column P5 of the child table. 

Is this correct?

tia,
Todd
MigrationUser 1  Monday, June 09, 2003 11:10 PM
have you tested it.?
MigrationUser 1  Tuesday, June 10, 2003 8:00 AM
Yes I did.
I am not getting the results I exepcted, and wanted to ensure my understanding was correct.
Just because the resuls are not what I exepcted, does not mean the code is wrong. It could mean my expectations are wrong, and I need to approach the problem another way.

The result which is unexpected is an error stating column P5 does not exist in the parent table. Which is true.  But why is that a problem? Column P5 is not a key column!

tia,
Todd
MigrationUser 1  Tuesday, June 10, 2003 11:16 AM
well, i'm not sure wether this is posible or not, but if this task were to assign to me, i would manuaaly do it row by row


void DoTheSum()
{
for each parent row{
 if( parentRow.GetChildRows bigger than 0)
  parentRow["columSum"] =  get it from the functions
 }
}

int  SumRow(DataRow row, DataSet dataset)
{

}

MigrationUser 1  Tuesday, June 10, 2003 10:08 PM
Here is what 'almost" works :


ds.Tables.Item("ParentTable").Columns.Add("P5Sum", GetType(Decimal), "Sum(Child(theDataRelation).P5)")


One confusing thing is that the first row of the next DataRelation group is included in the sum.
Example:
apple = 1
apple = 3
apple = 5
sum(apple) = 14
orange = 5 ' this row is included in the sum of apple.

If the DataRelation manages the sum function properly, then how could logic cause
this error in the sum? Is this a known bug or a logic problem ADO newbies encounter?

Any suggestions, comments ??
Can someone please clarify this?

tia,
Todd
MigrationUser 1  Friday, June 13, 2003 11:58 AM
I thought some may benefit from the  Johnny Papa aritcles on ADO
in the MSND magazine "Data Points" section.

You can find them on the web at:

http://msdn.microsoft.com/msdnmag/issues/02/11/datapoints 
http://msdn.microsoft.com/msdnmag/issues/02/02/data/default.aspx
'Expressions
http://msdn.microsoft.com/msdnmag/issues/03/01/datapoints/


hth someone,
Todd
MigrationUser 1  Friday, June 13, 2003 12:09 PM

You can use google to search for other answers

Custom Search

More Threads

• Controls Not Appearing on Windows Form
• Given ComponentModel.Component, I'd like to have a list of names (keys) of other components in the parent container.
• Compact framework SQL error
• checkedlistbox
• Menu links to utility programs howto?
• justify numeric value
• Problem using MessageFilter to capture arrow key event
• User controls will not show up in toolbox automatically
• call a client ddl from IE6 with activeX???
• VS.Net 2005 Beta 2 - DataGridView make hidden - update - make visible - missing data