如何获得最大数量? [英] How to get the biggest number?
本文介绍了如何获得最大数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获得最大的数字?
i我试图从我的数据库中的一个字段中获取最大数字,但这很奇怪,因为我使用这个简单的代码
How get the biggest number?
i am trying to get the biggest number from a field in my database but is it strange because i use this simple code
amenitiesExcel = dc.Hotel_Meals_TBLs.Select(Convert.ToInt32(a => a.CodeNumber)).Max();
当我编译查询时,我收到此错误:
and when i compile the query i receive this error:
Error 370 The type arguments for method 'System.Linq.Queryable.Select<TSource,TResult>(System.Linq.IQueryable<TSource>, System.Linq.Expressions.Expression<System.Func<TSource,TResult>>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
...数据库中的字段CodeNumber是Nvarchar数据类型,然后只填充数字,我需要存储最大的在这个领域的数字,你有任何想法或建议如何在这种情况下获得最大的数字
非常感谢你的支持。
干杯
...the field "CodeNumber" in the database is a Nvarchar Datatype then is filled only with number and i need to store the biggest number in this field ,do you have any idea or suggestion how i can get the biggest number in this case
Thanks so much for the support.
Cheers
推荐答案
你应该试试这个:
You should try this:
amenitiesExcel = dc.Hotel_Meals_TBLs.Max(a => Convert.ToInt32(a.CodeNumber));
或
or
amenitiesExcel = dc.Hotel_Meals_TBLs.Max(a => int.Parse(a.CodeNumber));
您不需要转换为int。只需更改您的查询,如下所示
You don''t need to Convert to int. Just change your Query like below
amenitiesExcel = dc.Hotel_Meals_TBLs.Max(a => a.CodeNumber);
希望这有帮助
Hope this helps
试试这个
Try this
int amenitiesExcel = 0;
amenitiesExcel = dc.Hotel_Meals_TBLs.Max(a => (int?)a.CodeNumber)?? 0;
这篇关于如何获得最大数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文