invalid XML identifier as required by FOR XML
I have a sp which returns me:
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')
But when I use ouptut as
Dim dr As New SqlDataAdapter(SqlCmd)
Dim tbl As New DataTable
dr.Fill(tbl)
I get an error
Column name 'Profit_£' contains an invalid XML identifier as required by FOR XML; '£'(0x00A3) is the first character at fault.
The problem is that I need have a raw name of column.
How can 开发者_开发知识库I struggle with that problem?
Its not legal to have a node name containing a £
symbol, so even if you could persuade mssql to allow you, whatever you did with the resulting XML would probably be rejected.
If you want XML and don't care that its badly formed, your going to have to return a regular result set to your .net app and build a string of xml manually.
Better to not use £
in the first place; ... as [Profit_Pounds]
.
Depending on what you want, FOR XML RAW would automatically escape the £ to a _x??? name.
You'll need to find another name for the columns with pound signs, as these are not valid for FOR XML
.
Consider using a currency abbreviation, such as Profit_GBP
, Delivered_Profit_GBP
.
The XML data format only supports unaccented US-ASCII characters A-z, some punctuation, and numbers. The pound sign (and Euro) are explicitly not supported.
精彩评论