<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Server01.aspx.cs" Inherits="Server01" %>
只保留以上这行代码。

.cs文件主要是:
public partial class Server01 : System.Web.UI.Page 

private string connString = @"server=BJ2-JIANGFJFDBSERVER;Trusted_Connection=false;database=TestDB;uid=sa;pwd=7929009"


protected void Page_Load(object sender, EventArgs e) 

Response.Clear(); 
Response.ContentType 
= "text/xml"
Response.Charset 
= "UTF-8"

getDataset(); 
// getXml(); 

Response.End(); 
}
 

private void getDataset() 

DataSet ds 
= new DataSet(); 
SqlConnection conn 
= new SqlConnection(connString); 

SqlCommand cmd 
= new SqlCommand("select * from TA",conn); 

SqlDataAdapter sda 
= new SqlDataAdapter(cmd); 

sda.Fill(ds); 
DataTable dt 
= ds.Tables[0]; 

StringBuilder xmlData 
= new StringBuilder(); 
xmlData.AppendLine(
@"<?xml version='1.0' encoding='UTF-8' ?>"); 
xmlData.AppendLine(
@"<root>"); 

foreach (DataRow dr in dt.Rows) 

string id = dr["id"].ToString(); 
string name = dr["name"].ToString(); 

xmlData.AppendLine(
@"<person"); 
xmlData.AppendLine(
@" id='"+id+""); 
xmlData.AppendLine(
@">"); 

xmlData.AppendLine(
@"<id>" + id + "</id>"); 
xmlData.AppendLine(
@"<name>" + name + "</name>"); 

xmlData.AppendLine(
@"</person>"); 
}
 
xmlData.AppendLine(
@"</root>"); 
Response.Write(xmlData.ToString()); 

}
 
private void getXml() 

StringBuilder xmlData 
= new StringBuilder(); 
xmlData.AppendLine(
@"<?xml version='1.0' encoding='UTF-8' ?>"); 
xmlData.AppendLine(
@"<root>根节点</root>"); 
xmlData.AppendLine(
@"根节点" + DateTime.Now.ToString() + ""); 
xmlData.AppendLine(
@"</root>"); 

Response.Write(xmlData.ToString()); 
}
 
}