Use Gruop By in Datatable.Compute() method
-
Dear All, I have the follow data in my Dataset1.Table(0)
col1 Col2 Col3 Col4 Col5 Qty
SS 111 SIN C 20 114
SS 111 SIN C 40 28
SS 111 SIN S 20 165
SS 111 SIN S 40 189I want to SUM(Qty) those are same color The result will like below
SSUM 111 SGSIN 20 279 (row1 + row3)
SSUM 111 SGSIN 40 217 (row2 + row4)I don’t want to loop and sum row by row. Is there any DataTable Method to get my result? If I use like this how will be my result?
Dataset1.Table(0).Compute(“Sum(Qty)”,”Group by Col1,Col2,Col3,Col5”)
Please, any suggestion for the best way. Thanks and Best Regards
-
Dear All, I have the follow data in my Dataset1.Table(0)
col1 Col2 Col3 Col4 Col5 Qty
SS 111 SIN C 20 114
SS 111 SIN C 40 28
SS 111 SIN S 20 165
SS 111 SIN S 40 189I want to SUM(Qty) those are same color The result will like below
SSUM 111 SGSIN 20 279 (row1 + row3)
SSUM 111 SGSIN 40 217 (row2 + row4)I don’t want to loop and sum row by row. Is there any DataTable Method to get my result? If I use like this how will be my result?
Dataset1.Table(0).Compute(“Sum(Qty)”,”Group by Col1,Col2,Col3,Col5”)
Please, any suggestion for the best way. Thanks and Best Regards
-
Dear All, I have the follow data in my Dataset1.Table(0)
col1 Col2 Col3 Col4 Col5 Qty
SS 111 SIN C 20 114
SS 111 SIN C 40 28
SS 111 SIN S 20 165
SS 111 SIN S 40 189I want to SUM(Qty) those are same color The result will like below
SSUM 111 SGSIN 20 279 (row1 + row3)
SSUM 111 SGSIN 40 217 (row2 + row4)I don’t want to loop and sum row by row. Is there any DataTable Method to get my result? If I use like this how will be my result?
Dataset1.Table(0).Compute(“Sum(Qty)”,”Group by Col1,Col2,Col3,Col5”)
Please, any suggestion for the best way. Thanks and Best Regards
Try this code: You have to select each group from the table. Declare a new DataTable Temp, now select the group values or distinct value in this datatable by following code( I am using C# language.)
DataTable TEMP = new DataTable();
TEMP=Dataset1.Table(0).DefaultView.ToTable(true,"Col4");Now the TEMP table will have following values in it- 1. C 2. S Now you can use loop and
DataSet.Compute("Sum(Qty)","Col4='"+TEMP.Rows[location][0].ToString()+"'")
method for data stored in TEMP. You can not use DataSet.Compute() method for multiple values as it is a single value function. :-D :-D :-D :-D :-D :-D For any further clearification please mail me at cybosoft@gmail.com