通过asp.net 生成xml文件

做项目的时候ext需要xml数据,顺手就用asp.net 导了个,如下:     

private   void   Page_Load(object   sender,   System.EventArgs   e)  
  {  
  SqlConnection   sc=new   SqlConnection("server=localhost;database=northwind;user   id=sa;password=");  
  sc.Open();  
  SqlCommand   scd=new   SqlCommand("SELECT   ProductID,   ProductName   FROM   Products   WHERE   CategoryID   =   1   ORDER   BY   ProductID",sc);  
  SqlDataAdapter   sda=new   SqlDataAdapter(scd);  
  DataSet   ds=new   DataSet();  
  sda.Fill(ds,"product");  
  sc.Close();  
   
  MemoryStream   ms=new   MemoryStream();  
  ds.WriteXml(ms,XmlWriteMode.IgnoreSchema);  
   
  ms.Position=0;  
  StreamReader   sr=new   StreamReader(ms);  
  Page.Response.Write(sr.ReadToEnd());  
  sr.Close();  
  }
posted @ 2008-03-30 00:49  Atpking  阅读(1020)  评论(1编辑  收藏  举报