c# - How to get readable xml from SQL Server database -
how can readable xml string sql server database?
in way xml string, set extjs textarea. text not readable:
public string getxml(string args) { string exmsg = ""; string result = ""; stringbuilder xmlresult = new stringbuilder(); dictionary<string, object> parameters = _ser.deserialize<dictionary<string, object>>(args); string id = parameters["id"].tostring(); try { system.data.sqlclient.sqlconnection cn = new system.data.sqlclient.sqlconnection(); cn.connectionstring = "data source=(local);initial catalog=methodsettings;user id=sa;password=sasa"; cn.open(); system.data.sqlclient.sqlcommand cmd = new system.data.sqlclient.sqlcommand(); cmd.connection = cn; cmd.commandtext = string.format("select methodargs methodsettings.dbo.methodparameters id ={0}", id); system.xml.xmlreader xmlr = cmd.executexmlreader(); xmlr.read(); if (xmlr != null) { xmlresult.appendline(xmlr.readouterxml()); result = xmlresult.tostring(); } } catch (exception ex) { exmsg = ex.message; } return _ser.serialize(result); }
you can use xdocument
's tostring()
method formatted xml string easily, if that's want :
system.xml.xmlreader xmlr = cmd.executexmlreader(); xdocument doc = xdocument.load(xmlr); doc.load(xmlr); var result = doc.tostring();
Comments
Post a Comment