读取数据库时将数据转成XML
using (SqlConnection conn=new SqlConnection(config)) { conn.Open(); SqlCommand comm = new SqlCommand(@"SELECT TOP 5 ClassID,ClassName,ClassNum FROM dbo.ClassRoom FOR XML AUTO",conn); XmlReader reader = comm.ExecuteXmlReader(); reader.Read(); while (!reader.EOF) { a += reader.ReadOuterXml(); } reader.Close(); return a; }