How to get DataType specific DataTable from XML
This is my code
string XMLReportFormat =@"<?xml version="1.0" encoding="utf-8" ?>
<Table>
<ReportBody>
<TableRow>
<ID>1</ID>
<ParentID>1</ParentID>
<Key>First1</Key>
</TableRow>
<TableRow>
<ID>4</ID>
<ParentID>1</ParentID>
<Key>FirstChild4</Key>
</TableRow>
</ReportBody>
</Table>";
StringReader sReader = new StringReader(XMLReportFormat);
DataSet ds = new DataSet();
if (sReader == null)
return null;
ds.ReadXml(sReader);
Here I am getting all DataType
of columns as String
.
I want some columns like ID
and ParentID
as Integer
sorry try this TryParse
http://msdn.microsoft.com/en-us/library/f02979c7.aspx
Yeah ! I found the answer.
This line helps me :)
The easiest way I have found is make sure your DataSet reads an xml schema. The schema will set the data types of the XML for your DataSet.
i.e.:
I was having an issue using Dynamic data in Microsoft Reports because everything coming from the XML was a string. I tried copying items to a new DataSet with dataTypes defined but this was much easier. You can have c# write a default schema for any xml file that you can then edit as needed.
I know this post is old but it helped me out so I thought I would share what I learned.