Querying a DataSet

Last post 07-07-2008 5:16 PM by qbui66. 6 replies.

Sort Posts:

  • Querying a DataSet

    07-04-2008, 2:49 PM
    • Member
      8 point Member
    • qbui66
    • Member since 10-14-2007, 11:22 PM
    • Posts 62

    Hi all,

    I have a dataset in my application, this dataset is bind to a drop-down-list.  Since it's a long list (about 2000 items) I want to use AJAX autocomplete to help the user to get approximately to what they want but I don't know how to query a dataset.  I cannot use the asmx web service as shown in the example since my web service is WCF and I believe that AJAX autocomplete cannot work with WCF.

    Please advice!  Thanks!

    QBui   

  • Re: Querying a DataSet

    07-04-2008, 8:26 PM

    qbui66,

    You'll need to change some specifics, but to turn a dataset into a string array (which is what the autocomplete web service returns) you'll want to do something like this:

            List<string> lst = new List<string>();

            DataSet ds = new DataSet();

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)

            {

                lst.Add(ds.Tables[0].Rows[i][0].ToString);

            }

            return lst.ToArray();

     

     

    You'll want to replace new DataSet() with your own dataset, of course.

    I'm afraid I don't completely understand the point about the WCF service, so I can't really address that.  Would turning the dataset into a string array make the WCF service unnecessary?

    James

    James Ashley, Magenic Technologies
    (james.ashley.magenic@gmail.com)
  • Re: Querying a DataSet

    07-05-2008, 3:09 PM
    • Member
      8 point Member
    • qbui66
    • Member since 10-14-2007, 11:22 PM
    • Posts 62

    James,

    The point about WCF is that my project needs to have WCF as a web service, not a .asmx web service.  The WCF web service get the data from the database and then bind the data to the textbox (I should say that it is the textbox, not the drop-down-list).  For examples out there, I see that autocomplete using the .asmx web service as shown: 

    <asp:TextBox runat="server" ID="myTextBox" Width="300" autocomplete="off" />
                <ajaxToolkit:AutoCompleteExtender
                    runat="server" 
                    BehaviorID="AutoCompleteEx"
                    ID="autoComplete1" 
                    TargetControlID="myTextBox"
                    ServicePath="AutoComplete.asmx" 
                    ServiceMethod="GetCompletionList"
                    MinimumPrefixLength="2" 
                    CompletionInterval="1000"
                    EnableCaching="true"
                    CompletionSetCount="20"
                    CompletionListCssClass="autocomplete_completionListElement" 
                    CompletionListItemCssClass="autocomplete_listItem" 
                    CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
                    DelimiterCharacters=";, :">
    The ServicePath references AutoComplete.asmx and I cannot reference my WCF web service (or it is available but I don't know how to?).
    So, my point is that I'm trying to query the dataset built from my WCF web service.  My WCF web service actually returned a string array and then I build the DataSet from it. 
    Since you mentioned turning the DataSet into a string array, would you tell me more on how to AutoComplete it?  Thanks!
    
     
  • Re: Querying a DataSet

    07-05-2008, 9:41 PM

    qb,

    You can use the demo autocomplete code as your template.  Here's some quick pseudo-code for turning the demo code into something that works with your SVC file.  I think we've already talked over 3. and 4., so if you can get 1. and 2. working (shouldn't be too hard, you just need to create a client proxy and invoke it)  I think you'll be good to go:

    [WebService(Namespace = "http://tempuri.org/")]

    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

    [System.Web.Script.Services.ScriptService]

    public class AutoComplete : WebService

    {

        public AutoComplete()

        {

        }

     

        [WebMethod]

        public string[] GetCompletionList(string prefixText, int count)

        {

            //pseudo code

            //1. call WCF svc

            //2. return dataset

            //3. convert dataset to string array

            //4. return array

        }

    James Ashley, Magenic Technologies
    (james.ashley.magenic@gmail.com)
  • Re: Querying a DataSet

    07-07-2008, 10:38 AM
    • Member
      8 point Member
    • qbui66
    • Member since 10-14-2007, 11:22 PM
    • Posts 62

    Hi James,

    Yes, I believe that it would be a good way.  I just wonder if we're able to query a DataSet?  My guess is that we are not to because if we can, you probably won't tell me to turn a DataSet into a String.

    QB

  • Re: Querying a DataSet

    07-07-2008, 11:10 AM
    Answer

    I think the autocomplete extender just expects to get a string array back, and doesn't really know how to handle anything else.  The signature it expects on the service it calls is pretty specific.

    BTW, based on your original question, I went ahead and tried to call a WCF service from an autocomplete extender, and it turns out to be pretty easy -- but the WCF service, just like an asmx service being called from client script, still needs to be written in a certain way and also needs to be in the same project: http://www.imaginativeuniversal.com/AjaxAutoCompleteExtenderWithWCF.aspx

    James

    James Ashley, Magenic Technologies
    (james.ashley.magenic@gmail.com)
  • Re: Querying a DataSet

    07-07-2008, 5:16 PM
    • Member
      8 point Member
    • qbui66
    • Member since 10-14-2007, 11:22 PM
    • Posts 62

    Hi James,

    Thanks very much for your answer.  I will try and see if I can follow your code to make it work in my case (Autocomplete using WCF service).

    QB

Page 1 of 1 (7 items)