[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();
}没测试
解决方案 »
- 网站打开后中间的部分出来现往左偏然后恢复
- Microsoft Visual Studio 2008 排版问题
- 失眠。精神折磨。
- [求助]asp.net和access的问题。急!!!
- 如何在page里定位程序自动添加的Button控件?
- 求Freetextbox 中文使用方法!
- 急啊!!在线等!! 关于引用 IE Web Controls 部署到另外一部服务器的问题。
- DropDownList 如何选中多行
- .net终极难点===框架集中“一框架中”滚动条往下拉时数据网格表头固定的问题??????
- 我安装了.net framwork,那时服务器能够正常显示aspx文件,可是几天后,我重装了iis后,就不照了。
- 我在母版页添加的login控件,在下一级目录下引用母版页不显示
- 有关多个表的数据转移的问题
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();
}
比如"中国",没有提示“中国人民”,这可能是因为数据表中Name字段没有“中国人民”