[WebMethod]
public string[] GetXX(string prefixText, int count)
{        List<string> list = new List<string>();        using (SqlConnection conn = new SqlConnection())
        {            
            conn.ConnectionString = WebConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString;            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "select peid,name from (select peid, name, ROW_NUMBER() OVER(ORDER BY peid desc) AS RowRank from changzhurenkou) as TempTable where peid like '%' + @peid  + '%' and RowRank < " + count;            cmd.Parameters.AddWithValue("peid", prefixText);            conn.Open();
            using (SqlDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection))
            {
                while (reader.Read())
                {
                    list.Add(reader["name"].ToString());
                    
                }
            }
        }
        return list.ToArray();
    }没测试

解决方案 »

  1.   

        [WebMethod]
        public string[] GetPeID (string prefixText, int count) 
        {
            List<string> queryList = new List<string>();
            SqlConnection cn = new SqlConnection(@"server=.\sqlexpress;uid=sa;pwd=;database=northwind");
            string strSql = "select top 10 peid,name from changzhurenkou where peid like @profixID order by peid";
            SqlCommand cmd = new SqlCommand(strSql, cn);
            cmd.Parameters.AddWithValue("@profixID", prefixText + "%");
            cn.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            int i = 0;
            while (dr.Read())
            {
                queryList.Add(dr.GetString(0));
            }
            cn.Close();
            return queryList.ToArray();
        } 
      

  2.   

    楼主是说不能自动提示中文吧?
    比如"中国",没有提示“中国人民”,这可能是因为数据表中Name字段没有“中国人民”