日期:2014-05-17  浏览次数:20427 次

关于 自动补全的问题 补全的信息有问题


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.SqlClient;
using System.Web.Script.Services;
using System.Configuration;



namespace HouseWeb
{
    /// <summary>
    /// HelpSerach 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
    // [System.Web.Script.Services.ScriptService]
    [ScriptService()]
    public class HelpSerach : System.Web.Services.WebService
    {

        [WebMethod]
        [ScriptMethod]
        public string[] GetProductName(string prefixText, int count)
        {
            List<string> suggestions = new List<string>();//声明一泛型集合
            string constr = ConfigurationManager.ConnectionStrings["DataSQLConnString"].ConnectionString;
            SqlConnection con = new SqlConnection(constr);
            con.Open();
            SqlCommand com = new SqlCommand("select distinct UserName from tb_UserInfo where UserName like @prefixname order by UserName", con);
            com.Parameters.Add("@prefixname", SqlDbType.NVarChar).Value = "%"+prefixText + "%";
            SqlDataReader sdr = com.ExecuteReader();
            while (sdr.Read())
            {
                suggestions.Add(sdr.GetString(0));
            }
            sdr.Close();
            con.Close();
            return suggestions.ToArray();
        }
    }
}


html代码如下 :


<asp:TextBox ID="txthelpcode" runat="server" CssClass="input01" Width="150"></asp:TextBox>