且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在数据表中获取列的SUM()时出错

更新时间:2023-12-01 18:17:28

我认为方法#1应该有效-只是不要比较您的 INT 列为空字符串!!

I believe method #1 should work - just don't compare your INT column to an empty string!!

因此,请使用以下内容:

So use something like this:

int sum = Convert.ToInt32(dtStock.Compute("Sum(TotalCases)", "[TotalCases] > 0"));

int sum = Convert.ToInt32(dtStock.Compute("Sum(TotalCases)", "[TotalCases] IS NOT NULL"));

或您需要的任何内容-只是不要使用 [TotalCases]<>'',因为它会将 INT 与一个空字符串进行比较-但这是行不通的!

or whatever you need - just don't use [TotalCases] <> '' since that compares an INT to an empty string - and that's not going to work!