将从数据库中查询的数据,转换成XML格式

 string connStr = "Server=178.88.1.121;initial catalog=test;User=sa;password=abc.DB";

        using (SqlConnection conn = new SqlConnection(connStr))
        {
            SqlCommand command = new SqlCommand("select top 4 * from h_emp_mstr", conn);
            conn.Open();
            DataSet ds = new DataSet();
            ds.DataSetName = "employeelist";
            ds.Load(command.ExecuteReader(), LoadOption.OverwriteChanges, "employee");
            Response.ContentType = "text/xml";
            ds.WriteXml(Response.OutputStream);
        }

posted @ 2012-06-08 14:52  Tom Fan  阅读(610)  评论(0编辑  收藏  举报