unit WinForm;

interface

uses
  System.Drawing, System.Collections, System.ComponentModel,
  System.Windows.Forms, System.Data,System.Data.SqlClient;

type
  TWinForm = class(System.Windows.Forms.Form)
  {$REGION 'Designer Managed Code'}
  strict private
    /// <summary>
    /// Required designer variable.
    /// </summary>
    Components: System.ComponentModel.Container;
    ListBox1: System.Windows.Forms.ListBox;
    TextBox1: System.Windows.Forms.TextBox;
    TextBox2: System.Windows.Forms.TextBox;
    Label1: System.Windows.Forms.Label;
    Label2: System.Windows.Forms.Label;
    Button1: System.Windows.Forms.Button;
    Button2: System.Windows.Forms.Button;
    GroupBox1: System.Windows.Forms.GroupBox;
    GroupBox2: System.Windows.Forms.GroupBox;
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    procedure InitializeComponent;
    procedure TWinForm_Load(sender: System.Object; e: System.EventArgs);
    procedure Button2_Click(sender: System.Object; e: System.EventArgs);
    procedure Button1_Click(sender: System.Object; e: System.EventArgs);
  {$ENDREGION}
  strict protected
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    procedure Dispose(Disposing: Boolean); override;
  private
    { Private Declarations }
  public
    constructor Create;
  end;

  [assembly: RuntimeRequiredAttribute(TypeOf(TWinForm))]

implementation

{$AUTOBOX ON}

{$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>
procedure TWinForm.InitializeComponent;
type
  TArrayOfSystem_Object = array of System.Object;
begin
  Self.ListBox1 := System.Windows.Forms.ListBox.Create;
  Self.TextBox1 := System.Windows.Forms.TextBox.Create;
  Self.TextBox2 := System.Windows.Forms.TextBox.Create;
  Self.Label1 := System.Windows.Forms.Label.Create;
  Self.Label2 := System.Windows.Forms.Label.Create;
  Self.Button1 := System.Windows.Forms.Button.Create;
  Self.Button2 := System.Windows.Forms.Button.Create;
  Self.GroupBox1 := System.Windows.Forms.GroupBox.Create;
  Self.GroupBox2 := System.Windows.Forms.GroupBox.Create;
  Self.GroupBox1.SuspendLayout;
  Self.GroupBox2.SuspendLayout;
  Self.SuspendLayout;
  // 
  // ListBox1
  // 
  Self.ListBox1.ItemHeight := 12;
  Self.ListBox1.Items.AddRange(TArrayOfSystem_Object.Create('ʾ'));
  Self.ListBox1.Location := System.Drawing.Point.Create(16, 24);
  Self.ListBox1.Name := 'ListBox1';
  Self.ListBox1.Size := System.Drawing.Size.Create(288, 232);
  Self.ListBox1.TabIndex := 0;
  // 
  // TextBox1
  // 
  Self.TextBox1.Location := System.Drawing.Point.Create(104, 40);
  Self.TextBox1.Name := 'TextBox1';
  Self.TextBox1.TabIndex := 1;
  Self.TextBox1.Text := 'Abc';
  // 
  // TextBox2
  // 
  Self.TextBox2.Location := System.Drawing.Point.Create(104, 104);
  Self.TextBox2.Name := 'TextBox2';
  Self.TextBox2.TabIndex := 2;
  Self.TextBox2.Text := 'Lenovo';
  // 
  // Label1
  // 
  Self.Label1.Location := System.Drawing.Point.Create(39, 45);
  Self.Label1.Name := 'Label1';
  Self.Label1.Size := System.Drawing.Size.Create(60, 23);
  Self.Label1.TabIndex := 3;
  Self.Label1.Text := '˿ID';
  // 
  // Label2
  // 
  Self.Label2.Location := System.Drawing.Point.Create(28, 109);
  Self.Label2.Name := 'Label2';
  Self.Label2.Size := System.Drawing.Size.Create(72, 23);
  Self.Label2.TabIndex := 4;
  Self.Label2.Text := '˾ƣ';
  // 
  // Button1
  // 
  Self.Button1.Location := System.Drawing.Point.Create(128, 200);
  Self.Button1.Name := 'Button1';
  Self.Button1.TabIndex := 5;
  Self.Button1.Text := '';
  Include(Self.Button1.Click, Self.Button1_Click);
  // 
  // Button2
  // 
  Self.Button2.Location := System.Drawing.Point.Create(232, 264);
  Self.Button2.Name := 'Button2';
  Self.Button2.TabIndex := 6;
  Self.Button2.Text := '';
  Include(Self.Button2.Click, Self.Button2_Click);
  // 
  // GroupBox1
  // 
  Self.GroupBox1.Controls.Add(Self.TextBox1);
  Self.GroupBox1.Controls.Add(Self.TextBox2);
  Self.GroupBox1.Controls.Add(Self.Button1);
  Self.GroupBox1.Controls.Add(Self.Label1);
  Self.GroupBox1.Controls.Add(Self.Label2);
  Self.GroupBox1.Location := System.Drawing.Point.Create(19, 8);
  Self.GroupBox1.Name := 'GroupBox1';
  Self.GroupBox1.Size := System.Drawing.Size.Create(240, 296);
  Self.GroupBox1.TabIndex := 9;
  Self.GroupBox1.TabStop := False;
  Self.GroupBox1.Text := 'ݣ˿ID͹˾ƣ';
  // 
  // GroupBox2
  // 
  Self.GroupBox2.Controls.Add(Self.ListBox1);
  Self.GroupBox2.Controls.Add(Self.Button2);
  Self.GroupBox2.Location := System.Drawing.Point.Create(296, 8);
  Self.GroupBox2.Name := 'GroupBox2';
  Self.GroupBox2.Size := System.Drawing.Size.Create(320, 296);
  Self.GroupBox2.TabIndex := 10;
  Self.GroupBox2.TabStop := False;
  Self.GroupBox2.Text := 'ݣ˿ID͹˾ƣ';
  // 
  // TWinForm
  // 
  Self.AutoScaleBaseSize := System.Drawing.Size.Create(6, 14);
  Self.ClientSize := System.Drawing.Size.Create(632, 318);
  Self.Controls.Add(Self.GroupBox2);
  Self.Controls.Add(Self.GroupBox1);
  Self.Name := 'TWinForm';
  Self.Text := 'ADO.NETԳ';
  Include(Self.Load, Self.TWinForm_Load);
  Self.GroupBox1.ResumeLayout(False);
  Self.GroupBox2.ResumeLayout(False);
  Self.ResumeLayout(False);
end;
{$ENDREGION}

procedure TWinForm.Dispose(Disposing: Boolean);
begin
  if Disposing then
  begin
    if Components <> nil then
      Components.Dispose();
  end;
  inherited Dispose(Disposing);
end;

constructor TWinForm.Create;
begin
  inherited Create;
  //
  // Required for Windows Form Designer support
  //
  InitializeComponent;
  //
  // TODO: Add any constructor code after InitializeComponent call
  //
end;

procedure TWinForm.Button1_Click(sender: System.Object; e: System.EventArgs);
var myConnection:SqlConnection;
    myCommand:SqlCommand;
    myReader: SqlDataReader;
    name,stu_id,str: string;
begin
       myConnection := SqlConnection.Create('Data Source = localhost; Integrated Security = SSPI; Initial Catalog = northwind');
       myCommand :=  myConnection.CreateCommand;
       name := TextBox1.Text;
       stu_id := TextBox2.Text;
       str := 'Insert into Customers(CustomerID,  CompanyName) values('''+name.trim+''', '''+stu_id.trim+''')';
       myCommand.CommandText := str;
       myConnection.Open;
       myCommand.ExecuteNonQuery;
       myConnection.close;
       TextBox1.Text := '';
       TextBox2.Text := '';
end;

procedure TWinForm.Button2_Click(sender: System.Object; e: System.EventArgs);
var myConnection:SqlConnection;
    myCommand:SqlCommand;
    myReader: SqlDataReader;
    str: string;
begin
      myConnection := SqlConnection.Create('Data Source = localhost; Integrated Security = SSPI; Initial Catalog = northwind');
      myCommand :=  myConnection.CreateCommand;
      myCommand.CommandText := 'select * from Customers';
      myConnection.Open;
      myReader := MyCommand.ExecuteReader;
      ListBox1.Items.Clear;
      while myReader.Read do
      begin
          str := myReader.GetString(0);
          str := str + ', ' + myReader.GetString(1);
          ListBox1.Items.Add(str);
      end;
      myConnection.close;
end;


procedure TWinForm.TWinForm_Load(sender: System.Object; e: System.EventArgs);
begin
      
end;

end.