读书人

GetEnumerator与foreach的有关问题

发布时间: 2012-08-31 12:55:03 作者: rapoo

GetEnumerator与foreach的问题?

C# code
    DataTable comment_dt=getComment.GetComment(topicID);                StringBuilder com_str =new StringBuilder();        foreach(var comAll in comment_dt){//遍历所有评论内容,拼接起来            com_str.Append(comAll.Nickname);             com_str.Append("@");              com_str.Append(comAll.Msg);            com_str.Append  ("#");            com_str.Append(comAll.Greattime);       


错误提示:

“System.Data.DataTable”不包含“GetEnumerator”的公共定义,因此 foreach 语句不能作用于“System.Data.DataTable”类型的变量

我看别人的代码直接就可以遍历的?

为什么我会提示这种东西?要用GetEnumerator的话,那怎么写?

谢谢各位了


[解决办法]
DataTable comment_dt=getComment.GetComment(topicID);

StringBuilder com_str =new StringBuilder();
foreach(DataRow comAll in comment_dt.Rows){//遍历所有评论内容,拼接起来
com_str.Append(comAll.Nickname);
com_str.Append("@");
com_str.Append(comAll.Msg);
com_str.Append ("#");
com_str.Append(comAll.Greattime);

读书人网 >asp.net

热点推荐