📄 datasets.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace DataSets
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class frmDataSets : System.Windows.Forms.Form
{
private System.Windows.Forms.Label lblEmployees;
private System.Windows.Forms.Label lblClients;
private System.Windows.Forms.Label lblOrders;
private System.Windows.Forms.ListBox lbEmployees;
private System.Windows.Forms.ListBox lbClients;
private System.Windows.Forms.DataGrid dgOrders;
private System.Windows.Forms.Button btnTable;
private System.Windows.Forms.Button btnRelation;
private System.Windows.Forms.Button btnClone;
private System.Windows.Forms.Button btnCopy;
private System.Data.SqlClient.SqlConnection cnNorthwind;
private System.Data.SqlClient.SqlCommand cmdSelectCustomers;
private System.Data.SqlClient.SqlDataAdapter daCustomers;
private System.Data.SqlClient.SqlCommand cmdSelectOrders;
private System.Data.SqlClient.SqlDataAdapter daOrders;
private System.Data.SqlClient.SqlCommand cmdSelectEmployees;
private System.Data.SqlClient.SqlDataAdapter daEmployees;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public frmDataSets()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lblEmployees = new System.Windows.Forms.Label();
this.lblClients = new System.Windows.Forms.Label();
this.lblOrders = new System.Windows.Forms.Label();
this.lbEmployees = new System.Windows.Forms.ListBox();
this.lbClients = new System.Windows.Forms.ListBox();
this.dgOrders = new System.Windows.Forms.DataGrid();
this.btnTable = new System.Windows.Forms.Button();
this.btnRelation = new System.Windows.Forms.Button();
this.btnClone = new System.Windows.Forms.Button();
this.btnCopy = new System.Windows.Forms.Button();
this.cnNorthwind = new System.Data.SqlClient.SqlConnection();
this.cmdSelectCustomers = new System.Data.SqlClient.SqlCommand();
this.daCustomers = new System.Data.SqlClient.SqlDataAdapter();
this.cmdSelectOrders = new System.Data.SqlClient.SqlCommand();
this.daOrders = new System.Data.SqlClient.SqlDataAdapter();
this.cmdSelectEmployees = new System.Data.SqlClient.SqlCommand();
this.daEmployees = new System.Data.SqlClient.SqlDataAdapter();
((System.ComponentModel.ISupportInitialize)(this.dgOrders)).BeginInit();
this.SuspendLayout();
//
// lblEmployees
//
this.lblEmployees.AutoSize = true;
this.lblEmployees.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lblEmployees.Location = new System.Drawing.Point(8, 8);
this.lblEmployees.Name = "lblEmployees";
this.lblEmployees.Size = new System.Drawing.Size(66, 13);
this.lblEmployees.TabIndex = 0;
this.lblEmployees.Text = "Employees:";
//
// lblClients
//
this.lblClients.AutoSize = true;
this.lblClients.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lblClients.Location = new System.Drawing.Point(200, 8);
this.lblClients.Name = "lblClients";
this.lblClients.Size = new System.Drawing.Size(44, 13);
this.lblClients.TabIndex = 1;
this.lblClients.Text = "Clients:";
//
// lblOrders
//
this.lblOrders.AutoSize = true;
this.lblOrders.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lblOrders.Location = new System.Drawing.Point(8, 136);
this.lblOrders.Name = "lblOrders";
this.lblOrders.Size = new System.Drawing.Size(43, 13);
this.lblOrders.TabIndex = 2;
this.lblOrders.Text = "Orders:";
//
// lbEmployees
//
this.lbEmployees.Location = new System.Drawing.Point(8, 24);
this.lbEmployees.Name = "lbEmployees";
this.lbEmployees.Size = new System.Drawing.Size(184, 95);
this.lbEmployees.TabIndex = 1;
//
// lbClients
//
this.lbClients.Location = new System.Drawing.Point(200, 24);
this.lbClients.Name = "lbClients";
this.lbClients.Size = new System.Drawing.Size(200, 95);
this.lbClients.TabIndex = 2;
//
// dgOrders
//
this.dgOrders.DataMember = "";
this.dgOrders.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dgOrders.Location = new System.Drawing.Point(8, 152);
this.dgOrders.Name = "dgOrders";
this.dgOrders.Size = new System.Drawing.Size(392, 208);
this.dgOrders.TabIndex = 3;
//
// btnTable
//
this.btnTable.Location = new System.Drawing.Point(416, 32);
this.btnTable.Name = "btnTable";
this.btnTable.Size = new System.Drawing.Size(96, 23);
this.btnTable.TabIndex = 4;
this.btnTable.Text = "Create Table";
//
// btnRelation
//
this.btnRelation.Location = new System.Drawing.Point(416, 64);
this.btnRelation.Name = "btnRelation";
this.btnRelation.Size = new System.Drawing.Size(96, 23);
this.btnRelation.TabIndex = 5;
this.btnRelation.Text = "Create Relation";
//
// btnClone
//
this.btnClone.Location = new System.Drawing.Point(416, 96);
this.btnClone.Name = "btnClone";
this.btnClone.Size = new System.Drawing.Size(96, 23);
this.btnClone.TabIndex = 6;
this.btnClone.Text = "Clone DataSet";
//
// btnCopy
//
this.btnCopy.Location = new System.Drawing.Point(416, 128);
this.btnCopy.Name = "btnCopy";
this.btnCopy.Size = new System.Drawing.Size(96, 23);
this.btnCopy.TabIndex = 7;
this.btnCopy.Text = "Copy DataSet";
//
// cnNorthwind
//
this.cnNorthwind.ConnectionString = "data source=localhost;initial catalog=nwind;integrated security=SSPI;persist " +
"security info=False;packet size=4096";
//
// cmdSelectCustomers
//
this.cmdSelectCustomers.CommandText = "SELECT CustomerID, CompanyName, City, Country, PostalCode, Region FROM CustomerLi" +
"st";
this.cmdSelectCustomers.Connection = this.cnNorthwind;
//
// daCustomers
//
this.daCustomers.SelectCommand = this.cmdSelectCustomers;
this.daCustomers.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "CustomerList", new System.Data.Common.DataColumnMapping[0])});
//
// cmdSelectOrders
//
this.cmdSelectOrders.CommandText = "SELECT EmployeeID, CustomerID, OrderID, OrderDate, Subtotal FROM OrderTotals";
this.cmdSelectOrders.Connection = this.cnNorthwind;
//
// daOrders
//
this.daOrders.SelectCommand = this.cmdSelectOrders;
this.daOrders.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "OrderTotals", new System.Data.Common.DataColumnMapping[0])});
//
// cmdSelectEmployees
//
this.cmdSelectEmployees.CommandText = "SELECT EmployeeID, FirstName, LastName FROM EmployeeList";
this.cmdSelectEmployees.Connection = this.cnNorthwind;
//
// daEmployees
//
this.daEmployees.SelectCommand = this.cmdSelectEmployees;
this.daEmployees.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Employees", new System.Data.Common.DataColumnMapping[0])});
//
// frmDataSets
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(520, 373);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnCopy,
this.btnClone,
this.btnRelation,
this.btnTable,
this.dgOrders,
this.lbClients,
this.lbEmployees,
this.lblOrders,
this.lblClients,
this.lblEmployees});
this.Name = "frmDataSets";
this.Text = "DataSets";
((System.ComponentModel.ISupportInitialize)(this.dgOrders)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new frmDataSets());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -