My customer gave me a webservice
which was written in ColdFusion and I have been trying to consume it with C#. I have been trying to convert XML to DataTabl
e but I am getting a DataTable
with no rows.
Here is my XML:
<?xml version='1.0' standalone='yes'?>
<dtFirms>
<NR>2</NR>
<NAME>CS Net - 2014</NAME>
<NRTIT>2 - 2014 - CS Net - 2014</NRTIT>
<PERIOD>7</PERIOD>
</dtFirms>
and this is my C# code. It always return empty DataTable. What am I doing wrong?
public DataTable ReadXmlIntoDataTable(string s) {
//create the DataTable that will hold the data
DataTable table = new DataTable("dtFirms");
try
{
//open the file using a Stream
using (Stream stream = GenerateStreamFromString(s))
{
//create the table with the appropriate column names
table.Columns.Add("NR", typeof(string));
table.Columns.Add("NAME", typeof(string));
table.Columns.Add("NRTIT", typeof(string));
table.Columns.Add("PERIOD", typeof(int));
//use ReadXml to read the XML stream
table.ReadXml(stream);
//return the results
return table;
}
}
catch (Exception ex)
{
return table;
}
}
public Stream GenerateStreamFromString(string s)
{
MemoryStream stream = new MemoryStream();
StreamWriter writer = new StreamWriter(stream);
writer.Write(s);
writer.Flush();
stream.Position = 0;
return stream;
}
It always return empty DataTable. What am I doing wrong? Please help me.