Search code examples
c#xmldatareader

How to read Xml value from dataReader column


I have a DataReader reader which contains a column called LoadData. LoadData contains data of type XML. Here is the sample of how my XML is.

<employee id=="1">
<name>Abc</name>
<city>Xyz</city>
</employee>

How can I read this using the reader. I have tried to use reader.GetString() but that does not work. Is there any other way? This question might sound repeated but so far all solutions that I have found are with SqlDataReader. I'm using just the DataReader and also please do not suggest solutions with LINQ as the project I'm working on uses a framework that does not support LINQ. Thank you.


Solution

  • Try to do following way.

    string xmlData = (string)reader["LoadData"]
    

    Now load string in XmlDocument or XDocument to parse it.