⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webform1.aspx.cs

📁 本程序主要解析.NET框架下的数据类型的转化技术
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Data.SqlClient;
using System.Xml;
using System.Xml.Xsl;

namespace XSLTDemo
{
	/// <summary>
	/// WebForm1 的摘要说明。
	/// </summary>
	public class WebForm1 : System.Web.UI.Page
	{
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			try
			{
				// 根据一个已有的DataSet对象创建一个新的XmlDataDocument对象
				DataSet ds = this.GetDataSet();
				XmlDataDocument xdd = new XmlDataDocument(ds);

				// 创建一个XslTranform对象并导入XSLT样式表文件
				XslTransform xslt = new XslTransform();
				xslt.Load(Server.MapPath("SuppliersProducts.xslt"));

				// 进行XSLT转换并输出结果到一个流对象
				MemoryStream ms = new MemoryStream();
				xslt.Transform(xdd, null, ms);
				ms.Seek(0, SeekOrigin.Begin);
				StreamReader sr = new StreamReader(ms);

				// 显示输出结果
				Response.Write(sr.ReadToEnd());
			}
			catch (Exception) {}
		}

		private DataSet GetDataSet()
		{
			try
			{
				// 创建SqlConnection对象、两个SqlDataAdapter对象以及一个DataSet对象
				SqlConnection con = new SqlConnection("server=localhost;initial catalog=Northwind;integrated security=true;");
				SqlDataAdapter daSuppliers = new SqlDataAdapter("SELECT * FROM Suppliers", con);
				SqlDataAdapter daProducts = new SqlDataAdapter("SELECT * FROM Products", con);
				DataSet ds = new DataSet("SuppliersProductsDS");

				// 打开连接,并用上面的两个SqlDataAdapter对象填充DataSet对象,最后关闭连接
				con.Open();
				daSuppliers.Fill(ds, "Suppliers");
				daProducts.Fill(ds, "Products");
				con.Close();

				// 在DataSet对象中添加必要的关系,该关系是一对多类型的
				ds.Relations.Add("SuppliersProducts", ds.Tables["Suppliers"].Columns["SupplierID"], ds.Tables["Products"].Columns["SupplierID"]).Nested = true;

				// 返回DataSet对象
				return ds;
			}
			catch (Exception) 
			{
				return null;
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -