我正在从Sharepoint列表中检索一些行。项目计数返回2,但是当我尝试使用GetDataTable方法获取DataTable中的项目时,它返回null。
这是我的代码:
public DataTable GetInbox()
{
using (SPSite site = new SPSite(SPContext.Current.Web.Url))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists.TryGetList("PromotionRecommendationList");
var q = new SPQuery()
{ //recommend by current user and status is change request means request is visible to requestor in editable mode
Query = @"<Where> <And>
<Eq>
<FieldRef Name='RecommendBy_EmpCode' />
<Value Type='Text'>"+obj_vemployee.GetEmployeeCode(GetLoggingName(CurrentUser.LoginName))+"</Value></Eq><Eq><FieldRef Name='Status' /><Value Type='Text'>"+Status.ChangeRquest+ "</Value></Eq></And><Or><Eq><FieldRef Name='assign_to_EmpCode' /><Value Type='Text'>" + obj_vemployee.GetEmployeeCode(GetLoggingName(CurrentUser.LoginName)) + "</Value></Eq></Or></Where>"
};
q.ViewFields = @"
<FieldRef Name='Request_No' />
<FieldRef Name='RecommendBy_EmpCode' />
<FieldRef Name='RecommendTo_EmpCode' />
<FieldRef Name='STATUS' />
<FieldRef Name='RequestStatus' />
";
var r = list.GetItems(q);
lblTEst.Text = list.Items.Count.ToString();//this is returning 2
DataTable dtResults = r.GetDataTable();//returning null
return dtResults;
}
}
return null;
}
答案 0 :(得分:0)
list.Items.Count返回列表中所有项目的编号,它不计算查询返回的项目,需要计算r变量中的项目(SPListItemCollection)
答案 1 :(得分:0)
这可能是由于您的caml查询未正确构建,因此没有为变量r
返回数据。您的or
仅包含一个条件,如果您不熟悉SharePoint caml schema