【发布时间】:2010-08-25 09:01:22
【问题描述】:
使用我在网络上找到的示例,我创建了一个函数,该函数使用 GetReparentedValue 为孩子重新父母。
但是,当我运行代码时,出现以下错误:无法在对象中插入重复键。
我明白为什么(因为我正在尝试让孩子重新成为父母,而新父母已经有了孩子,所以我需要知道新父母结构中孩子的 MAX 路径(层次结构),但我不明白我是怎么做到的我真的会这样做。
路径 0x58
旧路径 0x
新路径 0x68
SqlCommand command = new SqlCommand("UPDATE Structure SET " +
"Path = " + path + ".GetReparentedValue" +
"(" +
oldPath + ", " + newPath +
")" +
"ParentID = @id " +
"WHERE Path = " + path, _connection);
添加孩子时我必须这样做,所以我认为需要将其添加到上面的查询中,但我不知道path + ".GetDescendant(" + lastChildPath + ", NULL)
数据库表
StructureID int Unchecked
Path hierarchyid Unchecked
PathLevel ([Path].[GetLevel]()) Checked
Description nvarchar(50) Checked
ParentID int Checked
ParentPath ([Path].[GetAncestor]((1))) Checked
有人有什么建议吗?
在此先感谢您的帮助 :-)
克莱尔
【问题讨论】:
-
你能展示一下你的桌子是什么样子的吗?
-
你好罗纳德,我已经添加了表格
标签: sql-server tsql hierarchyid