日期:2014-05-16 浏览次数:20665 次
public string DataTableToXMLString(System.Data.DataTable dt) { if (dt == null) return null; System.Text.StringBuilder sXML = new System.Text.StringBuilder(); System.IO.StringWriter sWriter = new System.IO.StringWriter(sXML); System.Xml.XmlTextWriter xWriter = new System.Xml.XmlTextWriter(sWriter); if (string.IsNullOrEmpty(dt.TableName)) dt.TableName = "row"; try { dt.WriteXml(xWriter); return sXML.ToString(); } catch { } finally { sWriter.Close(); xWriter.Close(); } return null; } protected void Page_Load(object sender, EventArgs e) { string v1=Request.Form["v1"],v2=Request.Form["v2"]; if (string.IsNullOrEmpty(v1)&&string.IsNullOrEmpty(v2)){ DataTable dt; //通过v1,v2读取数据库填充DataTable string xml=DataTableToXMLString(dt);///// Response.ContentType = "text/xml";////////// Response.Write(xml);/////// Response.End();/////// } }