开发者

I want to get the maximum number in a particular column of sharepoint 2010 list

开发者 https://www.devze.com 2023-03-04 12:47 出处:网络
Below is the query that I am trying SPQuery query = new SPQuery(); query开发者_运维问答.RowLimit = 1;

Below is the query that I am trying

 SPQuery query = new SPQuery();
 query开发者_运维问答.RowLimit = 1;
 query.Query = "<Query><OrderBy><FieldRef Name='Identifier' Ascending='False' /></OrderBy></Query>";
 SPListItemCollection Items = list.GetItems(query);
 if (Items.Count > 0)
 {
 SPListItem item = Items[0];
 maxValue = (int)item["Identifier"];
 }

This is the error that I am getting *strong text*Specified cast is not valid.


What type is the "Identifier" column? It's not a field of SPListItem so I'm assuming it is the name of a column in your list.

Try:

var tempVal = item["Identifier"];

then put a breakpoint there and see what Visual Studio tells you about the structure and type of that item.

0

精彩评论

暂无评论...
验证码 换一张
取 消