1. 程式人生 > >讀取數據庫時將數據轉成XML

讀取數據庫時將數據轉成XML

lose code 取數據 pen ssr from command col for 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; }

讀取數據庫時將數據轉成XML