62,272
社区成员
发帖
与我相关
我的任务
分享
var list = new List<Category>()
{
new Category(1, 0) ,
new Category(2, 0) ,
new Category(3, 1) ,
new Category(4, 1) ,
new Category(5, 3) ,
new Category(6, 3)
};
var children = GetChildren(list, 1);
string sql = "delete from [table] where id in (" + String.Join(", ", children.Select( c => c.Id.ToString()).ToArray()) + ")";
Console.WriteLine(sql);
string allid = "";//定义全局变量保存ID
public void getCalculatorQTY(int ID)
{
if (allid == "")
{
allid = ID.ToString();
}
else
{
allid = allid + "," + ID.ToString();
}
DataTable dt = new DataTable();
string sql = "select id from table where pid=" + ID + "";
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
getCalculatorQTY(dt.Rows[i]["id"].ToString());
}
}
}
public class Category
{
public int Id { get; set; }
public string Name { get; set; }
public int ParentId { get; set; }
}
public List<Category> GetChildren(List<Category> list, int parentId)
{
var children = new List<Category>();
foreach (var item in list.Where(c => c.ParentId == parentId))
{
children.Add(item);
children.AddRange(GetChildren(list, item.Id));
}
return children;
}
//是父类
string ids = "";
ids += id + ",";
string ziID = "";
string sqqq = "select id from T_ProductClass where pid=" + id;
ziID = eu.AccessSearchValue(sqqq);