如何在Asp.Net和Sql中动态列表? [英] How do dynamic List in Asp.Net and Sql for this?
问题描述
我正在尝试获取xml值列表。我有像这样的xml列表(列中其他xml中的ID行数不同:
I 'm trying to get list of xml values . I have table with xml column like this(count of ID rows in other xml in column is different :
<Category>
<ID>A50</ID>
<ID>A51</ID>
<ID>A52</ID>
<ID>A53</ID>
</Category>
我的sql查询是这样的:
My sql query is like this :
DECLARE @id int = 1
SELECT
E.P.value('(ID)[@id]', 'nvarchar(MAX)')
FROM
Table
CROSS APPLY
xml.nodes('/Category') AS E(P)
它不起作用。但我需要得到每个节点( @id是为了这个 - 它将循环像1然后2等。)值到asp.net列表项/ texbox,从webform更改它。
我如何只获取值并将其输出到Asp.net列表中(我不知道节点多少也很难)?
Its not work .But i need to get each node(@id is for this - it will be loop like 1 then 2 etc.) value to asp.net List item/texbox , to change it from webform .
How can i get only values and output it on Asp.net List (i don't know how much will be nodes and it make difficult too) ?
推荐答案
这里XmlColumn是一个数据类型为xml的列。你的解决方案就在这里。只有你的才适合使用。如有任何问题请咨询。
Here XmlColumn is a comumn of data type xml .Your solution is here.just get is suit for yours and use.If there any problems then please ask.
DECLARE @xml_var XML
select @xml_var=[XmlColumn] from [SubscriberDB].[dbo].[tbl_MyTable]
SELECT
Category.query('./text()')
AS ID
FROM
@xml_var.nodes('/Category/ID')
AS Bike(Category);
输出:
ID
---
A50
A51
A52
A53
OUTPUT:
ID
---
A50
A51
A52
A53
这篇关于如何在Asp.Net和Sql中动态列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!