一聚教程网:一个值得你收藏的教程网站

热门教程

[ASP.net]从数据库中读取数据自动生成XML

时间:2022-06-30 10:38:33 编辑:袖梨 来源:一聚教程网

Program Ex:
=================
string sql = "SELECT id,name FROM content FOR XML AUTO,XMLDATA";
SqlConnection conn =new SqlConnection( System.Configuration.ConfigurationSettings.AppSettings["testDataBase"] );
SqlCommand cmd=new SqlCommand(sql,conn);
conn.Open();
XmlTextReader objXmlReader = (XmlTextReader)cmd.ExecuteXmlReader();
DataSet ds = new DataSet();
ds.DataSetName = "XML";
ds.ReadXml(objXmlReader,XmlReadMode.Fragment);
ds.WriteXml(Server.MapPath("XML.xml"));
conn.Close();

热门栏目