Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everybody,
I'm currently writing a new web service and i'm a little bit stuck.

I'm trying to write a method that will filter results from a SQL database based on attributes passed to the web service :-
[WebMethod]
    public XmlDocument getSearchResults(string Attributes)
    {
        XmlDocument results = //get stuff from sql
        return results;
    }

Now, I need to be able to filter on multiple attributes at once (for example red AND round, or whatever, you get the idea) but the number won't always be the same, so I need to loop through and change the sql command accordingly to add each attribute. Is this possible? do I just added multiple elements of the same type to the SOAP envelope? if so how do I process them? :confused::~

Thanks in advance.
Gib
Posted
Updated 15-Oct-10 3:28am
v2

1 solution

This is gunna be tuff, if u have the column names on the end thats calling the webservice your fine, but if not then thats gonna suck..

if you have the names you can basically make an array list on the Aspx side -

using system.collections()
   public XmlDocument callwebsvc()
     {
             arraylist arr = new arraylist();
             arr.add("columnName = '"+ textbox1.Text +"', columnTwoName = '" + textbox2.Text + "'");//or you could add them seperatly
             svc = new webserviceref.service();
             svc.QueryDB(arr.ToArray());
     }


so when your back at your web service you have a nice little array to work with..

 [webmethod]
public querydb(string[] arr){
    string sqlcommand = "select blabla from blabla"
    string where = "";
    for(i = 0; i < arr.length; arr++)
              where = t[i].tostring();
        }
    sqlcommand = sqlcommand + " where " + where;
//so your sqlcommand will be:
//select * from blabla where columnName = 'val1', columnTwoName = 'val2'
}


see what i mean? i did it before its handy enuf, just tricky
 
Share this answer
 
Comments
Gibb3h 15-Oct-10 9:49am    
ah ha, I never thought of passing an array, was too absorbed with XML!

I think that should do it hopefully, I'll give it a go, cheers! :)
[no name] 15-Oct-10 9:53am    
best of luck - wish i cud supply you with my old code :/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900