CAML Query: Multiple Query Fields Issue

Discussion in 'ASP .Net Web Services' started by Jon F., May 12, 2004.

  1. Jon F.

    Jon F. Guest

    I need to Create a CAML Query Dynamically with VB to a Sharepoint
    WebService GetListItems Method.

    The User Could Select 1 to X Number of IDs from a list Box. For a
    Database Id I would create the Query String Dynamically, but I can't
    figure out how to do this with CAML queries


    To Create Database SQL Query with VB would look something like this, (i
    don't know if this code works, its just to show an example)
    *************************
    Dim SelectStr As String
    Dim Element As String

    SelectStr = "Select * from table where "

    For Each Element in StringArray
    SelectStr += "ID=" & Element & " or "
    Next
    Dim Idx As Integer = SelectStr = LastIndexOf(" or ")
    SelectStr = SelectStr.Substring(0,Idx)
    **************************
    The Result is a sql String something like : "Select * from table where
    ID=1 or ID=5 Or ID=7 Or ID=89"


    The Problem I'm Having is Creating a CAML Query like the SQL Query
    above. I can't figure out the pattern of where the <Or> Tag needs to go
    based on the Number of Filter Fields. Example for two Fields the query
    would look like:
    <Where>
    <Or>
    <Eq>
    <FieldRef Name='ID'/>
    <Value Type='Number'>1</Value>
    </Eq>
    <Eq>
    <FieldRef Name='ID'/>
    <Value Type='Number'>5</Value>
    </Eq>
    </Or>
    </Where>

    But Placement of the <Or> Tag Changes as you add Fields:
    <Where>
    <Or> 'Added to Handle Third Field
    <Or>
    <Eq>
    <FieldRef Name='ID'/>
    <Value Type='Number'>1</Value>
    </Eq>
    <Eq>
    <FieldRef Name='ID'/>
    <Value Type='Number'>5</Value>
    </Eq>
    </Or>
    <Eq>
    <FieldRef Name='ID'/>
    <Value Type='Number'>7</Value>
    </Eq>
    </Or>
    </Where>


    Thanks,
    Jon

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Jon F., May 12, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. call_me_anything
    Replies:
    4
    Views:
    496
    Pete Becker
    Sep 30, 2007
  2. JP SIngh
    Replies:
    5
    Views:
    282
    Bob Barrows [MVP]
    Jan 24, 2006
  3. Mauricio Fernandez
    Replies:
    8
    Views:
    147
    Phil Tomson
    Jun 30, 2007
  4. Mauricio Fernandez
    Replies:
    15
    Views:
    240
    Mauricio Fernandez
    Oct 19, 2007
  5. Replies:
    0
    Views:
    311
Loading...

Share This Page