处理数据表计算方法? [英] Dealing with datatable compute method?

查看:84
本文介绍了处理数据表计算方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用类似的计算方法

I''m trying to use compute method like that

object sumObject;
        sumObject = dtbasket.Compute("Sum(total)", "");
        lbltotal.Text = (sumObject.ToString());




但这给了我这个错误
聚合函数Sum()和类型:String的用法无效.

请任何人帮忙解决这个问题,或给我另一种解决方案吗?




but it gives me this error
Invalid usage of aggregate function Sum() and Type: String.

Please could any one help me on this or give me another solution???

thanx in advance.

推荐答案

最可能的原因是,数据表中的列总数是使用无法求和的数据类型定义的.例如,如果total是一个字符串字段,则不能将其求和.检查基础数据类型,并在需要时将其更改为正确的数据类型.
The likeliest reason is that the column total in your data table is defined with a data type that cannot be summed. For example if total is a string field, it cannot be summed. Check the underlying data type and if needed, change it to proper data type.


计算方法不适用于字符串数据类型.如果您不想更改字段的数据类型而不是查询,则可以这样写:-

compute method not work on string datatype. if you don''t want to change datatype of your field than in query you can write like that:-

select  cast(isnull(FieldName,0)as  decimal) from TableName


比您可以使用Compute.它不会给出任何错误.但是如果您在总计字段中存储了非数字值,它将不起作用.


than you can use Compute. it will not give any error. but if in your total field you have stored non numeric value it will not work.


这篇关于处理数据表计算方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆