gpt4 book ai didi

.net - FOR XML 要求的无效 XML 标识符

转载 作者:数据小太阳 更新时间:2023-10-29 02:21:07 24 4
gpt4 key购买 nike

我有一个返回我的 sp:

Select 10 as Visits,5 as [Test_Drives],3 as Orders,'£5000' as [Profit_£],4 as Deliveries,'£6000' as [Delivered_Profit_£]

FOR XML PATH('CONTENT'),ROOT('SOMEROOT')

但是当我将输出用作

Dim dr As New SqlDataAdapter(SqlCmd)
Dim tbl As New DataTable
dr.Fill(tbl)

我得到一个错误

Column name 'Profit_£' contains an invalid XML identifier as required by FOR XML; '£'(0x00A3) is the first character at fault.

问题是我需要一个列的原始名称。

我该如何解决这个问题?

最佳答案

它的 not legal有一个包含 £ 符号的节点名称,因此即使您可以说服 mssql 允许您这样做,无论您对生成的 XML 做什么,都可能会被拒绝。

如果您需要 XML 并且不关心它的格式是否错误,您将不得不将常规结果集返回到您的 .net 应用程序并手动构建一个 xml 字符串。

一开始最好不要使用 £...作为 [Profit_Pounds]

根据您的需要,FOR XML RAW 会自动将 £ 转义为 _x???姓名。

关于.net - FOR XML 要求的无效 XML 标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7659955/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com