0

I am building a visual web part application with c# and i need to query items from my list, but i have to add some conditionals.

I am successfully querying ID and Title but I need another conditional to show items only if they are created earlier than example 5 May 2017.

I am trying the following query but it is not working and it shows me an error?

why?

please help me!

<Query>
 <Where>
  <And>
     <Lt>
        <FieldRef Name='ID' />
        <Value Type='Counter'>10</Value>
     </Lt>
        <Eq>
           <FieldRef Name='Title' />
           <Value Type='Text'>text</Value>
        </Eq>
        <Leq>
           <FieldRef Name='Created' />
           <Value IncludeTimeValue='TRUE' Type='DateTime'>2017-05-05T17:01:50Z</Value>
        </Leq>
  </And>
 </Where>
</Query>
1

I think the error in your query at this section, where you forget to add And

<And>
   <Eq>
       <FieldRef Name='Title' />
       <Value Type='Text'>text</Value>
    </Eq>
    <Leq>
       <FieldRef Name='Created' />
       <Value IncludeTimeValue='TRUE' Type='DateTime'>2017-05-05T17:01:50Z</Value>
    </Leq>
</And>

the final one should looks like

<Query>
   <Where>
      <And>
         <Lt>
    <FieldRef Name='ID' />
    <Value Type='Counter'>10</Value>
    </Lt>
         <And>
   <Eq>
       <FieldRef Name='Title' />
       <Value Type='Text'>text</Value>
    </Eq>
    <Leq>
       <FieldRef Name='Created' />
       <Value IncludeTimeValue='TRUE' Type='DateTime'>2017-05-05T17:01:50Z</Value>
    </Leq>
   </And>
      </And>
   </Where>
</Query>

My suggestion is to build your query with a CAML Query builder like (U2U) to avoid the syntax error

2

Try it as below:

<Where>
    <And>
        <Lt>
                <FieldRef Name='ID' />
                <Value Type='Counter'>10</Value>
        </Lt>
        <And>
            <Eq>
                       <FieldRef Name='Title' />
                       <Value Type='Text'>text</Value>
            </Eq>
            <Leq>
                       <FieldRef Name='Created' />
                       <Value IncludeTimeValue='TRUE' Type='DateTime'>2017-05-05T17:01:50Z</Value>
            </Leq>
        </And>
    </And>
</Where>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.