using System; using System.Web; using System.Collections; using System.Collections.Generic; using System.Web.Services; using System.Web.Services.Protocols; using System.Data; using System.Data.SqlClient; using System.Configuration; [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.Web.Script.Services.ScriptService] public class AutoComplete : WebService { string connectionString = string.Empty; DataTable dt = null; SqlCommand objCommnad = null; SqlDataAdapter da = null; SqlConnection con = null; public AutoComplete() { } [WebMethod] public string[] GetCompletionList(string prefixText, int count) { if (count == 0) { count = 10; } if (prefixText.Equals("xyz")) { return new string[0]; } Random random = new Random(); List<string> items = new List<string>(count); for (int i = 0; i < count; i++) { char c1 = (char)random.Next(65, 90); char c2 = (char)random.Next(97, 122); char c3 = (char)random.Next(97, 122); items.Add(prefixText + c1 + c2 + c3); } //return items.ToArray(); return getCompany(prefixText); /////////////////Rizwan Code Here \\\\\\\\\\\\\\\\\\\\\\\ } private string[] getCompany(string CompanyNameLike) { connectionString = ConfigurationManager.AppSettings["ConStr1"].ToString(); con = new SqlConnection(connectionString); try { con.Open(); objCommnad = new SqlCommand(); objCommnad.Connection = con; objCommnad.CommandType = CommandType.StoredProcedure; objCommnad.CommandText = "LU_Select_ProPerty"; objCommnad.Parameters.Add("@CompanyName", SqlDbType.VarChar).Value = CompanyNameLike; da = new SqlDataAdapter(objCommnad); dt = new DataTable(); da.Fill(dt); //return dt; } catch (Exception ex) { con.Close(); throw ex; } finally { con.Close(); } List<string> items = new List<string>(dt.Rows.Count); for (int i = 0; i < dt.Rows.Count; i++) { items.Add(dt.Rows[i]["pro_name"].ToString()); } return items.ToArray() ; } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)