读取数据库时将数据转成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;
            
        }

 

posted @ 2018-09-13 23:45  进阶的哈姆雷特  阅读(389)  评论(0编辑  收藏  举报