Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > CAML Query: Multiple Query Fields Issue

Reply
Thread Tools

CAML Query: Multiple Query Fields Issue

 
 
Jon F.
Guest
Posts: n/a
 
      05-12-2004
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!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[ANN] rocaml 0.6.0: fast, easy Ruby extensions in Objective Caml Mauricio Fernandez Ruby 15 10-19-2007 09:53 PM
print struct fields and its member structs' fields recursively, generically call_me_anything C++ 4 09-30-2007 10:12 PM
[ANN] rocaml: Ruby extensions in Objective Caml Mauricio Fernandez Ruby 8 06-30-2007 06:50 AM
Search for Multiple keywords in multiple fields JP SIngh ASP General 5 01-24-2006 01:53 PM
Netscape hidden fields - array - multiple fields with same name mark.reichman@rl.af.mil Javascript 0 07-17-2003 03:05 PM



Advertisments