这个小问题怎么解决啊!急救
这个小问题怎么解决啊!急救for (int j = 0; j < Category.Rows.Count(); j++)
{
CategoryParent += Category.Rows[i]["CategoryParent"]+",";
}
{
return Database.ExecuteDataset("Select * from PG_News_View where CategoryID in (""+CategoryParent+"")").Tables[0];
}
CategoryParent循环到最后变成CategoryParent=1,2,3,4,5,
怎么才能让最后一个不出现,号出来啊! --------------------编程问答-------------------- 1)可以在循环中添加判断
for (int j = 0; j < Category.Rows.Count(); j++)
{
if(j == Category.Rows.Count()-1)
{
CategoryParent += Category.Rows[i]["CategoryParent"];
}
else
{
CategoryParent += Category.Rows[i]["CategoryParent"]+",";
}
}
//--------------------------------------
2)或者在连接后使用substring去掉最后的分号.
--------------------编程问答--------------------
StringBuilder list=new StringBuilder();
for (int j = 0; j < Category.Rows.Count(); j++)
{
list.Append(Category.Rows[i]["CategoryParent"]);
if(j!= Category.Rows.Count()-1)
list.Append(",");
}
CategoryParent=sb.ToString();
补充:.NET技术 , C#