using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Data;
using System.Data.SqlClient;
public partial class autocomplete : System.Web.UI.Page
{
const string conString = WebConfigurationManager.ConnectionStrings["dpCompanyConnectionString"].ConnectionString;
public class ProductName
{
public string photoName { get; set; }
public string photoNumber { get; set; }
public List<ProductName> GetProduct(string key)
{
List<ProductName> results = new List<ProductName>();
SqlConnection con = new SqlConnection(conString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "select top 12 * from(select cname,Number,DELYES from pricelist where cname LIKE '%" + key + "%' union select cname,Number,DELYES from pricelist where Number LIKE '%" + key + "%')t order by len(Number),DELYES";
cmd.Parameters.AddWithValue("@keyword", key);
using (con)
{
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
ProductName search = new ProductName();
search.photoName = (string)reader["cname"];
search.photoNumber = (string)reader["Number"];
results.Add(search);
}
return results;
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
//string keyword = Request.Form["q"];
string keyword ="cd"; ProductName c = new ProductName();
c.GetProduct(keyword);
foreach (ProductName i in c)
{
Response.Write(i.photoName + "|" + i.photoNumber + "<br/>");
} }
}
如何才能让foreach可用?
解决方案 »
- 论坛的回复,引用怎么做
- MVC3怎么设置@Html.TextBoxFor这样的样式
- asp.net如何在gridview中显示图片!
- asp.net操作xml添加新结点
- 请问如何让RegularExpressionValidator 在TextBox非空的情况下才验证?
- ★★★★★★★★版主揭发倒粪贴!!!!很可恶!!!!!倒粪倒粪倒粪倒粪倒粪
- 框架参数传递问题
- 小菜一碟——一步一步用c#写论坛,V1.40源代码发布!
- asp.net mvc 缓存问题
- asp.net core 项目在iis8中只能上传小于30kb以下的文件
- MembershipUserCollection 填充到 DataSet
- TreeView滚动条的问题(100分),如果解决的好可再开贴追加分!
foreach (ProductName i in c)改成:foreach (ProductName i in c.GetProduct(keyword))