public string[] GetString(string prefixText, int count){ System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string>(count); System.Data.DataSet ds = new System.Data.DataSet(); //这里是我在数据库中取数据的代码 其中SqlHelper类是项目中的取数据基类 //string strSql = string.Format("SELECT TOP {0} NAME FROM CengWei WHERE NAME LIKE '{1}%' ORDER BY NAME",count,prefixText); //ds = SqlHelper.Query(strSql); //for (int i = 0; i < ds.Tables[0].Rows.Count; i++) //{ // list.Add(ds.Tables[0].Rows[i][0].ToString()); //} for (int i = 0; i < count; i++) { list.Add(prefixText+i.ToString()); } return list.ToArray(); }
webService代码: using System; using System.Web; using System.Collections; using System.Web.Services; using System.Web.Services.Protocols; /// <summary> /// AutoComplete 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] //下面是必须的,否则功能无法实现 [System.Web.Script.Services.ScriptService] public class AutoComplete : System.Web.Services.WebService { public AutoComplete () { //如果使用设计的组件,请取消注释以下行 //InitializeComponent(); } [WebMethod] public string HelloWorld() { return "Hello World"; } [WebMethod] public string[] GetString(string prefixText, int count){ System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string>(count); System.Data.DataSet ds = new System.Data.DataSet(); //这里是我在数据库中取数据的代码 其中SqlHelper类是项目中的取数据基类 //string strSql = string.Format("SELECT TOP {0} NAME FROM CengWei WHERE NAME LIKE '{1}%' ORDER BY NAME",count,prefixText); //ds = SqlHelper.Query(strSql); //for (int i = 0; i < ds.Tables[0].Rows.Count; i++) //{ // list.Add(ds.Tables[0].Rows[i][0].ToString()); //} for (int i = 0; i < count; i++) { list.Add(prefixText+i.ToString()); } return list.ToArray(); } } 有哪里不对的地方还请大家指教