typelist+="typeid=" + typeid + " or "
整个程序是这样的,是两个表,但是红色的我不是很明白,大家帮忙讲解一下。谢谢!
connstring = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection conn = new SqlConnection(connstring);
string sqltype="select typeid from newstype where parentid=3";
satype = new SqlDataAdapter(sqltype,conn);
satype.Fill(ds,"newstype");
if(!Page.IsPostBack)
{
int counttype;
counttype=ds.Tables["newstype"].Rows.Count;
int i;
int typeid;
string typelist="";
if(counttype!=0)
for (i=0;i<=counttype-1;i++)
{
typeid=(int)ds.Tables["newstype"].Rows[0]["typeid"];
typelist+="typeid=" + typeid + " or ";
}
typelist=typelist.Remove (typelist.Length -4,4);
string sql="select top 6 id,title,time from newsreport where inuse='1' and " + typelist +" order by time desc";
sa = new SqlDataAdapter(sql,conn);
sa.Fill(ds,"newsreport");
string title="";
int count;
int id;
string t="";
count=ds.Tables["newsreport"].Rows.Count;
int j;
if(count!=0)
{
for(j=0;j<=count-1;j++)
{
title=ds.Tables["newsreport"].Rows[j]["title"].ToString().Trim();
t=ds.Tables["newsreport"].Rows[j]["time"].ToString().Trim();
string time=t.Substring(0,9);
id=(int)ds.Tables["newsreport"].Rows[j]["id"];
Literal1.Text +="<img src='images/arrow-blue.gif' width='8' height='9' align='absmiddle'> <a href='/Normal/news/readnews.asp?id="+ id +"' target='_blank'>"+ title +"("+ time +")</a><br>";
}
}
}