数据库有个字段叫keyWord
存储的数据格式是这样的 制度,规则 这是关键字
我要读取这个关键字 跟其他条数据的关键字匹配
然后ID从大到小获取前十条显示到repeater上面public void Repeater1Bind()
{
int id = Convert.ToInt16(Request.QueryString["ArticleID"]);
JobLord_Job.Model.RL_Article model = new JobLord_Job.BLL.RL_Article().GetModel(id);
String[] words = model.KeyWords.Split(',');
for (int i = 0; i < words.Length; i++)
{
DataTable list = new JobLord_Job.BLL.RL_Article().GetList(1000, "KeyWords like'%" + words[i] + "%'", "ID DESC").Tables[0];
this.Repeater1.DataSource = list;
this.Repeater1.DataBind();
}
}
每个用逗号分隔的关键字能查到的数据条数都不一样 我怎么控制最后D从大到小获取前十条显示到repeater上面
存储的数据格式是这样的 制度,规则 这是关键字
我要读取这个关键字 跟其他条数据的关键字匹配
然后ID从大到小获取前十条显示到repeater上面public void Repeater1Bind()
{
int id = Convert.ToInt16(Request.QueryString["ArticleID"]);
JobLord_Job.Model.RL_Article model = new JobLord_Job.BLL.RL_Article().GetModel(id);
String[] words = model.KeyWords.Split(',');
for (int i = 0; i < words.Length; i++)
{
DataTable list = new JobLord_Job.BLL.RL_Article().GetList(1000, "KeyWords like'%" + words[i] + "%'", "ID DESC").Tables[0];
this.Repeater1.DataSource = list;
this.Repeater1.DataBind();
}
}
每个用逗号分隔的关键字能查到的数据条数都不一样 我怎么控制最后D从大到小获取前十条显示到repeater上面
解决方案 »
- ████████ 页面跳转问题,急急急 ████████在线急等
- Functions这个函数需要引用哪些命名空间和类库?
- 请教一个问题!
- 【精华】如何让ascx里2个DroDdownList联动起来?100分+
- 循环执行多条insert语句后,出现:ORA-01000: 超出打开游标的最大数
- 如何做可以排序的新闻系统,
- 总是,,提示我。。excel 是只读的,,之后就在process中多了一个excel 进程
- _______________________难题______________________问高手________________________
- 用crystal report9.2做报表下一页按钮不起作用?
- 菜鸟求助!
- 触发器
- vs2005 没有AJAX母板页
2。从大到小排序 (sql:DESC)
3。取前10条 (sql: TOP 10) 完事。。
??
然后再查 select distinct top 10 * from xxx where order by id desc
你这个方法应该已经实现 条数 筛选 排序的功能了
{
JobLord_Job.BLL.Pub_Class bll_pub = new JobLord_Job.BLL.Pub_Class();
int id = Convert.ToInt16(Request.QueryString["ArticleID"]);
JobLord_Job.Model.RL_Article model = new JobLord_Job.BLL.RL_Article().GetModel(id);
String[] words = model.KeyWords.Split(',');
string sql = "";
for (int i = 0; i < words.Length; i++)
{
sql = "select distinct top 10 * from RL_Article where KeyWords like'%" + words[i] + "%'";
}
this.Repeater1.DataSource = bll_pub.GetQuery(sql + " order by ID desc").Tables[0];
this.Repeater1.DataBind();
}你们的意思说是这样吗?
把第二个参数改成 匹配所有关键字就行了
{
JobLord_Job.BLL.Pub_Class bll_pub = new JobLord_Job.BLL.Pub_Class();
int id = Convert.ToInt16(Request.QueryString["ArticleID"]);
JobLord_Job.Model.RL_Article model = new JobLord_Job.BLL.RL_Article().GetModel(id);
String[] words = model.KeyWords.Split(',');
string sql = "select distinct top 10 * from RL_Article where 1=1 ";
for (int i = 0; i < words.Length; i++)
{
if(words.Length > 1&&i!=words.Length-1)
{
sql += " KeyWords like'%" + words[i] + "%' or ";
}else
{
sql += " KeyWords like'%" + words[i] + "%'";
}
}
this.Repeater1.DataSource = bll_pub.GetQuery(sql + " order by ID desc").Tables[0];
this.Repeater1.DataBind();
}
{
int id = Convert.ToInt16(Request.QueryString["ArticleID"]);
JobLord_Job.Model.RL_Article model = new JobLord_Job.BLL.RL_Article().GetModel(id);
String[] words = model.KeyWords.Split(',');
for (int i = 0; i < words.Length; i++)
{
DataTable list = new JobLord_Job.BLL.RL_Article().GetList(1000, "KeyWords like'%" + words[i] + "%'", "ID DESC").Tables[0];
list.DefaultView.Sort = "ID DESC";
this.Repeater1.DataSource = list;
this.Repeater1.DataBind();
}
}
2。从大到小排序 (sql:DESC)
3。取前10条 (sql: TOP 10)很条理嘛
偶吧好厉害!!!
{
JobLord_Job.BLL.Pub_Class bll_pub = new JobLord_Job.BLL.Pub_Class();
int id = Convert.ToInt16(Request.QueryString["ArticleID"]);
JobLord_Job.Model.RL_Article model = new JobLord_Job.BLL.RL_Article().GetModel(id);
String[] words = model.KeyWords.Split(',');
string sql = "select distinct top 10 * from RL_Article "; for (int i = 0; i < words.Length; i++)
{
if(words.Length > 1&&i!=words.Length-1)
{
sql += " where KeyWords like'%" + words[i] + "%' or";
}else
{
sql += " where KeyWords like'%" + words[i] + "%'";
}
}
this.Repeater1.DataSource = bll_pub.GetQuery(sql + " order by ID desc").Tables[0];
this.Repeater1.DataBind();
}
这样应该可以
实际原理很简单。。(就是拼一个sql语句) 如果还有什么问题。。你可以在 this.Repeater1.DataSource = bll_pub.GetQuery(sql + " order by ID desc").Tables[0];
这一行打个断点。。看最后生成的 sql 语句是什么,直接放 SQL SERVER 里面运行一下。。就很明显了
from RL_Article where KeyWords like '%aaaa%')
where 序号<=10
{
JobLord_Job.BLL.Pub_Class bll_pub = new JobLord_Job.BLL.Pub_Class();
int id = Convert.ToInt16(Request.QueryString["ArticleID"]);
JobLord_Job.Model.RL_Article model = new JobLord_Job.BLL.RL_Article().GetModel(id);
String[] words = model.KeyWords.Split(',');
string sql = "select distinct top 10 * from RL_Article ";
string sqlstr=" "
for (int i = 0; i < words.Length; i++)
{
if(words.Length > 1&&i!=words.Length-1)
{
sqlstr+= " KeyWords like'%" + words[i] + "%' or";
}else
{
sqlstr+= " KeyWords like'%" + words[i] + "%'";
}
}
if(words.Length > 1)
{
sqlstr=sqlstr.SubString(0,sqlstr.lengt-2);
}
sql =sql + sqlstr;
this.Repeater1.DataSource = bll_pub.GetQuery(sql + " order by ID desc").Tables[0];
this.Repeater1.DataBind();
}