Today I have found a strange behavior of the SPQuery class. My code has the following structure:
…
SPList list = web.Lists["MyList"];
SPQuery query = new SPQuery();
foreach (DataRow row in table.Rows)
{
query.Query = "<Where>Some CAML Query with a row dependant condition</Where>";
SPListItemCollection items = list.GetItems(query);
…
}
…
After the first iteration, the SPListItemCollection items always contains the same items, although the Query property of the query has been changed in the bucle. To resolve it I have putted the initialization of the SPQuery inside the bucle:
…
SPList list = web.Lists["MyList"];
foreach (DataRow row in table.Rows)
{
SPQuery query = new SPQuery();
query.Query = "<Where>Some CAML Query with a row dependant condition</Where>";
SPListItemCollection items = list.GetItems(query);
…
}
…
And now all works normally.