简体   繁体   中英

Using IN Element with other Elements in SPQuery

I'm trying to retrieve items from list using this Query:

query.Query = 
@"<Where>
    <And>
        <And>
            <Geq>
                <FieldRef Name='Date' /><Value Type='DateTime' IncludeTimeValue='TRUE'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(dateFrom) + @"</Value>
            </Geq>
            <Leq>
                <FieldRef Name='Date' /><Value Type='DateTime' IncludeTimeValue='TRUE'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(dateTo) + @"</Value>
            </Leq>
        </And>
        <In>
            <FieldRef Name='Employee' LookupId='TRUE' />
                <Values>
                    <Value Type='int'>1</Value>
                    <Value Type='int'>3</Value>
                </Values>
        </In>
    </And>
</Where>";

On runtime i get the following exception: SPException: One or more field types are not installed properly. Go to the list settings page to delete these fields on line List.GetItems(query) .

If i modify SPQuery like this:

query.Query =
@"<Where>
    <And>
        <Geq>
            <FieldRef Name='Date' /><Value Type='DateTime' IncludeTimeValue='TRUE'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(dateFrom) + @"</Value>
        </Geq>
        <Leq>
            <FieldRef Name='Date' /><Value Type='DateTime' IncludeTimeValue='TRUE'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(dateTo) + @"</Value>
        </Leq>
    </And>
</Where>";

or this:

query.Query =
@"<Where>
    <In>
        <FieldRef Name='Employee' LookupId='TRUE' />
            <Values>
                <Value Type='int'>1</Value>
                <Value Type='int'>3</Value>
            </Values>
    </In>
</Where>";

everything is working perfectly.

The problem was in reusing SPQuery object, surprisingly. So I create a new SPQuery and everything is OK.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM