📄 03dsschema.aspx.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.Data.SqlClient;
namespace AdDataSet
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Button Button3;
protected System.Web.UI.WebControls.Button Button4;
protected System.Web.UI.WebControls.DataGrid dgShow1;
protected System.Web.UI.WebControls.DataGrid dgShow2;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
}
#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.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Button3.Click += new System.EventHandler(this.Button3_Click);
this.Button4.Click += new System.EventHandler(this.Button4_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
DataSet ds1;
//使用DataSet API
ds1 = new DataSet();
ds1.Tables.Add("Customers");
ds1.Tables[0].Columns.Add("custid",typeof(int));
ds1.Tables[0].Columns.Add("custname",typeof(string));
ds1.Tables.Add("Orders");
ds1.Tables[1].Columns.Add("custid",typeof(int));
ds1.Tables[1].Columns.Add("orderid",typeof(int));
ds1.Relations.Add(ds1.Tables["Customers"].Columns["custid"],ds1.Tables["Orders"].Columns["custid"]);
dgShow1.DataSource = ds1.Tables[0].DefaultView;
dgShow1.DataBind();
dgShow2.DataSource = ds1.Tables[1].DefaultView;
dgShow2.DataBind();
ds1.WriteXmlSchema(Server.MapPath("out.xsd"));
}
private void Button2_Click(object sender, System.EventArgs e)
{
DataSet ds2;
//使用Schema From SQLServer
ds2 = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(
"Select * from customers;Select * from Orders",
"server=(local);uid=sa;pwd=111;database=northwind");
da.FillSchema(ds2,SchemaType.Source);
ds2.Tables[0].TableName = "Customers";
ds2.Tables[1].TableName = "Orders";
ds2.Relations.Add(ds2.Tables["Customers"].Columns["customerid"],
ds2.Tables["Orders"].Columns["customerid"]);
dgShow1.DataSource = ds2.Tables["Customers"].DefaultView;
dgShow1.DataBind();
dgShow2.DataSource = ds2.Tables["Orders"].DefaultView;
dgShow2.DataBind();
}
private void Button3_Click(object sender, System.EventArgs e)
{
DataSet ds3;
//从文件中读取
ds3 = new DataSet();
ds3.ReadXmlSchema(Server.MapPath("customer.xsd"));
dgShow1.DataSource = ds3.Tables[0].DefaultView;
dgShow1.DataBind();
}
private void Button4_Click(object sender, System.EventArgs e)
{
DataSet ds4;
//使用InforXmlSchema
ds4 = new DataSet();
ds4.InferXmlSchema(Server.MapPath("customer.xml"),null);
dgShow1.DataSource = ds4.Tables[0].DefaultView;
dgShow1.DataBind();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -