zoukankan      html  css  js  c++  java
  • 获取一条记录的数据并生成XML文档

     1
     2    //获取一条记录的数据并生成XML文档
     3    private void ExportOne(string KeyID)
     4    {
     5        string strSQL = "Select * From PO Where HmNumPO='" + KeyID + "'";
     6
     7        SqlConnection connection = new SqlConnection("Data Source=(local);Initial Catalog=CSS;Persist Security Info=True;User ID=sa;Password=123456");
     8        SqlCommand cmd = new SqlCommand(strSQL, connection);
     9
    10        connection.Open();
    11        SqlDataReader rdr = cmd.ExecuteReader();
    12        rdr.Read();
    13
    14        Response.Clear();
    15        Response.Buffer = true;
    16        Response.ContentType = "text/xml";
    17        Response.Charset = "utf-8";
    18
    19
    20        Response.AppendHeader("Content-Disposition""attachment;filename=" + rdr["HmNumPO"].ToString() + ".xml");
    21        // 如果设置为 GetEncoding("GB2312");导出的文件将会出现乱码!!!
    22        Response.ContentEncoding = System.Text.Encoding.UTF8;
    23        //Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
    24        //DBNull tmpDBNull = new DBNull();
    25        
    26
    27        Response.Write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
    28        Response.Write("<Root>");
    29        Response.Write("<Title></Title>");
    30        Response.Write("<Content>");
    31        Response.Write("<Section4>");
    32        Response.Write("    <Date>" + rdr["HmNumPO"].ToString() + "</Date>");
    33        Response.Write("</Section4>");
    34        Response.Write("<Section6>");
    35        Response.Write("    <SupplierName>" + rdr["CostcoPONum"].ToString()  + "</SupplierName>");
    36        Response.Write("    <QuoteProvidedBy>" + rdr["SHCity"].ToString() + " Liu</QuoteProvidedBy>");
    37        Response.Write("    <Position>" + rdr["SHZip"].ToString() + "</Position>");
    38        Response.Write("</Section6>");
    39        Response.Write("<Section7>");
    40        Response.Write("   <Phone>" + rdr["SHPhone"].ToString() + "</Phone>");
    41        Response.Write("    <Email>" + rdr["SHEmail"].ToString() + "</Email>");
    42        Response.Write("</Section7>");
    43        Response.Write("<Section9>");
    44        Response.Write("    <Description>" + rdr["CostcoPONum"].ToString() + "</Description>");
    45        Response.Write("</Section9>");
    46        Response.Write("<Section10>");
    47        Response.Write("    <Description>" + rdr["CostcoPONum"].ToString() + "</Description>");
    48        Response.Write("</Section10>");
    49
    50        Response.Write("</Content>");
    51        Response.Write("</Root>");
    52
    53
    54        Response.Flush();
    55        Response.End();        
    56    
    57    }

    58
    59
  • 相关阅读:
    Ex 6_20 最优二叉搜索树..._第六次作业
    Ex 6_12 凸多边形的最优三角剖分..._第六次作业
    Ex 6_9 某个字符串处理语言提供了一个将字符串一分为二的基本操作..._第六次作业
    Ex 6_4 判断序列是否由合法单词组成..._第六次作业
    maven配置阿里云镜像时(私服设置~JEECG)
    node、npm、webpack、vue-cli傻傻分不清?
    设计模式~观察者模式和发布订阅模式的比较:
    前端~定位属性position(relative、absolute、fixed)的分析
    debounce防抖函数减少函数调用的逻辑分析(包裹上时间的外衣,在时间还没来时,kill)
    js原生滚动与使用插件better-scroll不起作用原因
  • 原文地址:https://www.cnblogs.com/liuweitoo/p/914825.html
Copyright © 2011-2022 走看看