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去掉最后的分号.
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();