📄 subform.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OracleClient;
namespace WinDemoOne
{
/// <summary>
/// SubForm 的摘要说明。
/// </summary>
public class SubForm : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dgEmp;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
OracleDataAdapter adapter = null;
public SubForm()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.dgEmp = new System.Windows.Forms.DataGrid();
((System.ComponentModel.ISupportInitialize)(this.dgEmp)).BeginInit();
this.SuspendLayout();
//
// dgEmp
//
this.dgEmp.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dgEmp.DataMember = "";
this.dgEmp.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dgEmp.Location = new System.Drawing.Point(8, 8);
this.dgEmp.Name = "dgEmp";
this.dgEmp.Size = new System.Drawing.Size(512, 320);
this.dgEmp.TabIndex = 0;
//
// SubForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(528, 338);
this.Controls.Add(this.dgEmp);
this.Name = "SubForm";
this.Text = "SubForm";
this.Load += new System.EventHandler(this.SubForm_Load);
this.Closed += new System.EventHandler(this.SubForm_Closed);
((System.ComponentModel.ISupportInitialize)(this.dgEmp)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void SubForm_Load(object sender, System.EventArgs e)
{
string connectionString = "user id=scott;data source=oralsea;password=tiger";
string sql = "select * from emp";
adapter = new OracleDataAdapter(sql, connectionString);
OracleCommandBuilder builder = new OracleCommandBuilder(adapter);
adapter.InsertCommand = builder.GetInsertCommand();
adapter.UpdateCommand = builder.GetUpdateCommand();
adapter.DeleteCommand = builder.GetDeleteCommand();
DataTable dt = new DataTable();
adapter.Fill(dt);
dgEmp.DataSource = dt;
}
private void SubForm_Closed(object sender, System.EventArgs e)
{
adapter.Update((DataTable)dgEmp.DataSource);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -