Skip to content

Sum funiction in datatable

ismail ka

Asked Dec 28, 2008, 6:14 AM EST1 answer
Share
LinkedInX

i have this table records in data table

datatable name is dt.

this datatable constrain these records

company name            money1              money2

cm1                               100                  50

cm2                               70                    30

cm1                               40                    60

 

i want same company must be in same line and amounts must be total amoun.

for example:

company name                    money1                 money2

cm1                                   140                            110         (2 line in one line with total money amount)

cm2                                   70                               30  

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Bechir Bejaoui
    0
    You can use the DataColumn.Expression of your data table, but it is not the best solution

    create a new data column and add it to the data table

    Code
     DataColumn money1Column = new DataColumn();
     money1Column.DataType = System.Type.GetType("System.Double");
     money1Column.ColumnName = "Sum of cm1";
     money1Column.Expression = "IIF(CompanyName == cm1,Sum(money1),0 )";

    Code
    DataColumn money2Column = new DataColumn();
     money2Column.DataType = System.Type.GetType("System.Double");
     money2Column.ColumnName = "Sum of cm1";
     money2Column.Expression = "IIF(CompanyName == cm1,Sum(money2),0 )";
    0