I am really new to SharePoint, and I came across an issue that is driving me crazy. I am trying to use CAML Query to get a specific list item. My query works on hard coded condition, but not when I pass in the value using a variable. Here is my code:
foreach (SPGroup group in groups)
{
queryTeams.Query = @"<Where>
<Eq>
<FieldRef Name='GroupTeams' />
<Value Type='User'>" + group.Name + @"</Value>
</Eq>
</Where>
"; // group.Name = Pharmacist Assistants
SPListItemCollection itemsTeams = listTeams.GetItems(queryTeams);
if (itemsTeams.Count > 0)
{
//do stuff
}
And here is the hard coded query that returns values:
queryTeams.Query = @"<Where>
<Eq>
<FieldRef Name='GroupTeams' />
<Value Type='User'>Pharmacist Assistants</Value>
</Eq>
</Where>";
Please help me figure out what am I doing wrong.
@
is causing issue.