| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 521 人关注过本帖
标题:一句C#的语句我不明白!!
只看楼主 加入收藏
lyf
Rank: 1
等 级:新手上路
帖 子:238
专家分:0
注 册:2005-11-17
收藏
 问题点数:0 回复次数:8 
一句C#的语句我不明白!!
由于对C#不是很了解,所以这句话我无法理解

typelist+="typeid=" + typeid + " or "
搜索更多相关主题的帖子: 语句 
2006-04-30 09:55
lisir123
Rank: 1
等 级:新手上路
帖 子:215
专家分:0
注 册:2005-12-16
收藏
得分:0 
字符串连接
2006-04-30 10:04
lyf
Rank: 1
等 级:新手上路
帖 子:238
专家分:0
注 册:2005-11-17
收藏
得分:0 

我知道是字符串的连接,其中 typeid是我的一个已定义的字符,但是我没能理解具体意思!!!


2006-04-30 10:07
water123456
Rank: 5Rank: 5
等 级:贵宾
威 望:15
帖 子:3208
专家分:5
注 册:2006-2-21
收藏
得分:0 
typelist+="typeid=" + typeid + " or "
你的这一句我还没有看明白,后面没有什么语句了吗?

让我们风风火火的过一生,别平平淡淡过一年。
2006-04-30 12:29
xugang
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2005-7-10
收藏
得分:0 
"typeiid"这个是字符串  +typeiid+ 这个是变量  "or"这个是字符串,假设typeiid的值是"Welcom",typelist的初始值是空那么通过这个语句后他的值就是typeid=Welcom or
2006-04-30 12:46
water123456
Rank: 5Rank: 5
等 级:贵宾
威 望:15
帖 子:3208
专家分:5
注 册:2006-2-21
收藏
得分:0 
可是楼主的意思是仅仅字符串联接吗?我感觉楼主不真的是想问这些的,要仅是这些的话,楼主一定能看得懂的.

让我们风风火火的过一生,别平平淡淡过一年。
2006-04-30 12:58
lyf
Rank: 1
等 级:新手上路
帖 子:238
专家分:0
注 册:2005-11-17
收藏
得分:0 

整个程序是这样的,是两个表,但是红色的我不是很明白,大家帮忙讲解一下。谢谢!

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>";

}

}

}


2006-04-30 13:41
lyf
Rank: 1
等 级:新手上路
帖 子:238
专家分:0
注 册:2005-11-17
收藏
得分:0 
哎,发上去怎么不是红色的部分了。红色的应该是上面当中的这些语句:

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";


2006-04-30 13:42
water123456
Rank: 5Rank: 5
等 级:贵宾
威 望:15
帖 子:3208
专家分:5
注 册:2006-2-21
收藏
得分:0 
typelist+="typeid=" + typeid + " or ";这一段通过循环构造条件.
当退出循环的时候,就把你下面的SQL条件构造好了.(所以还算是字符串联接.)

可是你的这一句我就有些不明白了
typelist=typelist.Remove (typelist.Length -4,4);
为什么要在总的字符上删除最后4个啦,你可以把你数据表发上来看看吗?

让我们风风火火的过一生,别平平淡淡过一年。
2006-04-30 21:19
快速回复:一句C#的语句我不明白!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017302 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved