I am trying to get customers with a matching name from a SharePoint list I tried with:
XmlDocument doc = new XmlDocument();
doc.LoadXml("<Query><Where><Lt><FieldRef Name=\"CustomerName\"/><Value Type=\"Text\">" + customerName + "</Value></Lt></Where></Query>");
XmlNode listQuery = doc.SelectSingleNode("//Query");
XmlNode n = sharePoint.listsObj.GetListI开发者_如何学编程tems(listName, null, listQuery, null, null, null, null);
nsmgr = new XmlNamespaceManager(n.OwnerDocument.NameTable);
nsmgr.AddNamespace("z", "#RowsetSchema");
nsmgr.AddNamespace("rs", "urn:schemas-microsoft-com:rowset");
XmlNodeList itemNodeList = n.SelectNodes("rs:data/z:row", nsmgr);
But in itemNodeList I get a customer with a name that is not similar at all to the parameter (customerName) I use in the query.
If I don't pass on the query I get all customers from the list.
Any ideas?
Thanks in advance.
If you want to get names that match exactly then use the Eq tag
For example from
- Smith
- Smith-Jones
- Jones
the following
<Query><Where><Eq><FieldRef Name="CustomerName"/><Value Type="Text">Smith</Value></Eq></Where></Query>
would return
- Smith
If you want to return names that contain the string then use the Contains tag
<Query><Where><Contains><FieldRef Name="CustomerName"/><Value Type="Text">Smith</Value></Contains></Where></Query>
would return
- Smith-Jones
- Jones
Have a look at the U2U CAML Builder
http://www.u2u.net/res/Tools/CamlQueryBuilder.aspx
精彩评论