> Dear Expert!
> I'm trying sum DataTable but command 2 very slow, please help!
>
>
> 1. very quick
> object sumCol1 = table.Compute("SUM(COL1)", "[COL2] ='" + _CODE + "'");
>
> //cDateEnd format string
> 2. //Sum very slow with DateColumn.
> object sumCol1 = table.Compute("SUM(COL1)", "[COL2] ='" + _CODE + "' AND [COLDATE] <='" + cDateEnd + "'");
>
>
>
> FaceBook: Can Cu
Anh,
Instead of table.Compute you could use Linq. ie:
1)
var sumCol1 = table.AsEnumerable().Where(x => x.Field<string>("Col2") == _CODE).Sum(x => x.Field<decimal>("Col1");
2)
// instead of a date string use a DateTime. ie:
// dDateEnd = DateTime.Now;
var sumCol1 = table.AsEnumerable().Where(x => x.Field<string>("Col2") == _CODE && x.Field<DateTime>("ColDate") <= dDateEnd).Sum(x => x.Field<decimal>("Col1");
PS: If the data is not changing in grid, then doing this directly on backend would be better.
Cetin Basoz
Give some sample data in code for your question - here is the tool you need to generate the codeMy Blog
PostgreSQL - World's most advanced open source databaseMongoDb Certified Developer
MongoDb Certified DBA
Flutter for mobile, for web & desktop.
The way to
Go.
How to create a Minimal, Reproducible Example