public partial class controls_Bulletin : System.Web.UI.UserControl
{
private SqlCommand Command;
private SqlConnection Connection;
private SqlDataAdapter DataAdapter;
private DataTable NewsTable;
private XmlDocument XmlDoc;
//protected Panel NoPicturePan;
private void DataLoad()
{
this.EnableViewState = false;
{
this.XmlDoc = new XmlDocument();
this.XmlDoc.Load(base.Request.PhysicalApplicationPath + "Config/AppConfig.config");
byte num1 = Convert.ToByte(this.XmlDoc.GetElementsByTagName("TopImgNum").Item(0).Attributes["value"].Value);
byte num2 = Convert.ToByte(this.XmlDoc.GetElementsByTagName("TopNewsNum").Item(0).Attributes["value"].Value);
{
this.NewsTable = new DataTable();
this.Connection = new SqlConnection(DataProvider.ConnectionString);
this.Command = new SqlCommand();
this.Command.Connection = this.Connection;
this.Command.CommandText = "Select Top 1 Articleid,Classid,Title,AddTime,HighLight,Hits,IndexTop From Article where Classid in (24,4) Order By sortid desc,addtime Desc ";
this.DataAdapter = new SqlDataAdapter();
this.DataAdapter.SelectCommand = this.Command;
this.DataAdapter.Fill(this.NewsTable);
this.Command.Dispose();
this.DataAdapter.Dispose();
this.Connection.Dispose();
this.NewsTable.Columns.Add("ClassName", typeof(string));
for (int num3 = 0; num3 < this.NewsTable.Rows.Count; num3++)
{
for (int num4 = 0; num4 < NavigateTree.InfinityTree.Rows.Count; num4++)
{
if (Convert.ToInt32(this.NewsTable.Rows[num3]["Classid"]) == Convert.ToInt32(NavigateTree.InfinityTree.Rows[num4]["Classid"]))
{
this.NewsTable.Rows[num3]["ClassName"] = NavigateTree.InfinityTree.Rows[num4]["ClassName"];
}
}
}
this.ArticleRpt.DataSource = this.NewsTable;
this.ArticleRpt.DataBind();
this.NewsTable.Dispose();
}
}
}
protected static string Format(string instr, int count, bool hl)
{
instr = OutPut.OutString(instr, count);
instr = OutPut.HeighLight(instr, hl);
return instr;
}
protected static string Format(string instr, int count, DateTime dt, bool hl)
{
instr = OutPut.OutString(instr, count);
instr = OutPut.HeighLight(instr, hl);
instr = instr + OutPut.GetNewImage(dt);
return instr;
}
protected void Page_Load(object sender, EventArgs e)
{
this.DataLoad();
}
}
------解决思路----------------------
where Classid in (24,4)
你是想取 Classid 等于 24 和 4 的各一条是这样的吗?
那么需要使用联合查询
Select Top 1 Articleid,Classid,Title,AddTime,HighLight,Hits,IndexTop From Article where Classid = 24
union
Select Top 1 Articleid,Classid,Title,AddTime,HighLight,Hits,IndexTop From Article where Classid = 4
Order By sortid desc,addtime Desc
------解决思路----------------------
选择top 1就是指显示查询出来的第一条数据而已的!!!
------解决思路----------------------
Select?Articleid,Article.Classid,Title,AddTime,HighLight,Hits,IndexTop?From?Article?
INNER?JOIN?
?(SELECT?MIN(Articleid)?AS?ID,Classid??FROM?Article
?WHERE?Classid?in?(24,4)?
?GROUP?BY?Classid)t?ON?Article.Articleid=t.ID
?Order?By?sortid?desc,addtime?DESC
这些小错误自己还搞不定啊……
------解决思路----------------------
你第一个问题控制显示顺序,在后面加order by
select Articleid,Classid,Title,AddTime,HighLight,Hits,IndexTop from (
select ROW_NUMBER() over(partition by classid order by sortid desc,AddTime desc) num,* from Article where Classid in (24,4)) t
where t.num=1 order by Classid desc
第二个问题,想每个里面提取两条数据
select Articleid,Classid,Title,AddTime,HighLight,Hits,IndexTop from (
select ROW_NUMBER() over(partition by classid order by sortid desc,AddTime desc) num,* from Article where Classid in (24,4)) t
where t.num<=2 order by Classid desc