c# - 如何修改sql server中的xml节点

标签 c# asp.net sql-server

我的表中有一个名为“Content_Html”的 xml 列,其中的数据如下所示:

 <root>
      <Category>Cover Impression</Category>
      <Title>Mystery of the Wolves</Title>
      <Month>April</Month>
      ...
      ...
    </root>

我正在尝试替换 <Category> 下的元素从 Cover Impression 到 Cover Impressions,在替换之后,我的这个类别的表格应该看起来像

<Category>Cover Impressions</Category>

我查看了这篇文章 (http://stackoverflow.com/questions/7316712/how-to-rename-xml-node-name-in-a-sql-server) 以了解我的问题,但不完全是我的问题寻找。

有人能给我指出正确的方向吗?

根据下面的建议我尝试了这个:

declare @newValue XML
select @newValue = 'Cover Impressions'
update dbo.content 
set content_html.modify('replace value of (/root/Category/text())[1] with sql:variable("@newValue")')

但给我“无法在 ntext 上调用方法”错误 谢谢,

最佳答案

你可以这样试试..

对于这段代码..

    <Sample>
  <NodeOne>Value1</NodeOne>
  <NodeTwo>Value2</NodeTwo>
  <NodeThree>OldValue</NodeThree>
</Sample>

用“NewValue”替换 NodeThree 中的“OldValue”。

 DECLARE @newValue varchar(50)
 SELECT @newValue = 'NewValue'

 UPDATE [Product]
 SET ProductXml.modify('replace value of (/Sample/NodeThree/text())[1] with sql:variable("@newValue")')

请为 more information 完成此操作

关于c# - 如何修改sql server中的xml节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8174181/

相关文章:

c# - Ninject - (usercontrol) 不包含采用 0 个参数的构造函数

c# - 如何使用 System.Threading 模拟下载速度

sql - 在多个数据库中查找重复值

c# - WPF 中的屏幕分辨率问题?

c# - C#Selenium如何单击嵌入的youtube视频的播放按钮

c# - Entity Framework 4 约定

sql-server - SQL Server 查询占用 100% CPU 并运行数小时

sql - 使用动态行和列创建 PIVOT - SQL Server 2016

C# MVC 使用 HMAC 签名参数实现 API

c# - 一个 View 上的登录和注册表单 MVC3 Razor