Home > Archive > MS SQL XML > October 2005 > method of getting sql xml









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author method of getting sql xml
Robert Jenkin

2005-10-31, 8:24 pm

string sSQL = @"select * from sites FOR XML AUTO, ELEMENTS";
oSystemCommand = new SqlCommand(sSQL, SqlConnSystem);
oDataReader = oSystemCommand.ExecuteReader();
oDataReader.Read();
string sXML="";
if (oDataReader.HasRows)
{
sXML = "<data>" + oDataReader.GetString(0).Trim() + "</data>";
//sXML = oDataReader.GetString(0).Trim();
}
System.Console.WriteLine(sXML);
StringReader osr = new StringReader(sXML) ;
xmlser = new XmlSerializer(typeof
(data));
data oSites = (data)xmlser.Deserialize(osr);


the above code is used to get entries from sites table as xml.
The data reader is used to get the xml data and then add <data> tags with
out the parent tags deserialize errors

thanks

bob
Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com