将数据插入到 ntext xml 列(无法调用 ntext 错误的方法) [英] Inserting data to ntext xml column (Cannot call methods on ntext error)

查看:27
本文介绍了将数据插入到 ntext xml 列(无法调用 ntext 错误的方法)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含 ntext 数据类型的 XML 列的表.

I have a table include XML column with ntext data type.

CREATE TABLE #Testing 
(
    Id int identity,
    content ntext
)

INSERT INTO #Testing
VALUES (N'<?xml version="1.0" encoding="UTF-8"?>
<Data <BankAcc><Bankname value="TEST Qərib Bank "/><AccNum value="TEST1221"/></BankAcc>
</Data>')

我想将此数据 插入到现有的ntext 数据类型xml 列中,代码如下

I want to insert this data <Owner value="Qərib"/> into existing ntext data type xml column with code below

 update #Testing
 set content.modify(N'insert <Owner value="Qərib"/> into (/Data)[1]')

但我收到一个错误:

消息 258,级别 15,状态 1,第 12 行
无法在 ntext 上调用方法

Msg 258, Level 15, State 1, Line 12
Cannot call methods on ntext

所以我尝试使用演员

update #Testing
 set cast(content as varchar(max)).modify(N'insert <Owner value="Qərib"/> into (/Data)[1]')

然后我收到此错误消息:

then I got this error message:

消息 102,级别 15,状态 1,第 12 行
'(' 附近的语法不正确.

Msg 102, Level 15, State 1, Line 12
Incorrect syntax near '('.

有什么解决办法吗?

推荐答案

将您的数据类型转换为 nvarchar(max)、varchar(max) 或 varbinary(max)

convert your data type to nvarchar(max), varchar(max) or varbinary(max)

重要!ntext、text 和 image 数据类型将在 SQL Server 的未来版本中删除.避免在新的开发工作中使用这些数据类型,并计划修改当前使用它们的应用程序.请改用 nvarchar(max)、varchar(max) 和 varbinary(max).

IMPORTANT! ntext, text, and image data types will be removed in a future version of SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead.

参考

如果它是正确的 xml,那么 XML 数据类型将最适合

If it is proper xml then XML data type will fit best

这篇关于将数据插入到 ntext xml 列(无法调用 ntext 错误的方法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆