Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
what i want to do is to keep my datatable in cache so that each time my webmethod called from the ajax autocomplete extender my data table dosen't gets filled from database again and again. To be brief i dont want to interact with database everytime i press a key in textbox. can this be done? Also The Ajax autocomplete extender is working dead slow why? my code is as below:
XML
[System.Web.Script.Services.ScriptMethod()]
    [System.Web.Services.WebMethod]
    public static List<string> GetCountries(string prefixText, int count)
    {
        DataTable dt = new DataTable();
        User objUser = new User();
        dt = objUser.GetDatatable();

        string Text = prefixText.ToUpper().ToString();
        List<string> LST = new List<string>();

         var query = from t in dt.AsEnumerable()
                     where t.Field<string>("DeptName").ToUpper().Contains(Text)
                     select new
                    {
                        DeptName = t.Field<string>("DeptName"),


                    };

         foreach (var i in query.Take(5))
         {
           LST.Add(i.DeptName.ToString().Trim());
         }

             return LST;
    }

an caching be done in webmethod?Thank you.
Posted
Comments
Taha Akhtar 19-Nov-13 10:10am    
you can use cache in webmethod and below is the right solution for fast execution

1 solution

Use below code .... it will speed up your execution a while ....

C#
[System.Web.Script.Services.ScriptMethod()]
       [System.Web.Services.WebMethod]
       public static List<string> GetCountries(string prefixText, int count)
       {
           DataTable dt = new DataTable();
           User objUser = new User();
           dt = objUser.GetDatatable();

           prefixText = prefixText.ToUpper();
           var query = (from DataRow r in dt.Rows
                       let DeptName = r.Field<string>("DeptName")
                        where DeptName.ToUpper().Contains(prefixText)
                       select DeptName).Take(5).ToList();
           return query;
       }


Try to execute this logic in sql server rather then trying to keep the result in cache... that will be the best solution ...... :D
 
Share this answer
 
v3

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