Click here to Skip to main content
15,899,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 :
XML
<Category>
  <ID>A50</ID>
  <ID>A51</ID>
  <ID>A52</ID>
  <ID>A53</ID>
</Category>



My sql query is like this :
SQL
DECLARE @id int = 1
 SELECT 
  E.P.value('(ID)[@id]', 'nvarchar(MAX)') 
FROM 
   Table
 CROSS APPLY
     xml.nodes('/Category') AS E(P)

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) ?
Posted
Updated 25-Dec-15 1:29am
v2

1 solution

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.
SQL
  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);




OUTPUT:
ID
---
A50
A51
A52
A53
 
Share this answer
 
v3
Comments
Андрей Голубцов 25-Dec-15 10:06am    
I have a question . If i want to send it to asp.net List and make row editable how i can make this ? If i don't know how many rows i will have?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900