62,050
社区成员
发帖
与我相关
我的任务
分享
string connectionString = ConfigurationManager.AppSettings["InsusConnectionString"];
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection (connectionString);
string strSql="SELECT * FROM [NewsType]";
SqlDataAdapter da = new SqlDataAdapter (strSql,conn);
DataSet ds = new DataSet ();
conn.Open ();
da.Fill (ds);
conn.Close ();
Response.Write("<?xml version=\"1.0\"?>");
Response.Write(ds.GetXml ());
Response.ContentType = "text/xml";
Response.End();
}
private static void DemonstrateGetXml()
{
// Create a DataSet with one table containing
// two columns and 10 rows.
DataSet dataSet = new DataSet("dataSet");
DataTable table = dataSet.Tables.Add("Items");
table.Columns.Add("id", typeof(int));
table.Columns.Add("Item", typeof(string));
// Add ten rows.
DataRow row;
for(int i = 0; i <10;i++)
{
row = table.NewRow();
row["id"]= i;
row["Item"]= "Item" + i;
table.Rows.Add(row);
}
// Display the DataSet contents as XML.
Console.WriteLine( dataSet.GetXml() );
}