zoukankan      html  css  js  c++  java
  • 学习 SQL 语句 Insert、Update、Delete

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls, Grids, DBGrids, DB, ADODB;
    
    type
      TForm1 = class(TForm)
        DBGrid1: TDBGrid;
        DataSource1: TDataSource;
        ADOConnection1: TADOConnection;
        ADODataSet1: TADODataSet;
        ADOCommand1: TADOCommand;
        Panel1: TPanel;
        Button1: TButton;
        Button2: TButton;
        Button3: TButton;
        Button4: TButton;
        procedure FormCreate(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
        procedure Button4Click(Sender: TObject);
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    //添加
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      try
        ADOCommand1.CommandText := 'INSERT INTO country VALUES("AAA", "BBB", "CCC", 111, 222)';
        ADOCommand1.Execute;
    
        ADOCommand1.CommandText :=
          'INSERT INTO country(Name,Capital,Continent) VALUES("XXX", "YYY", "ZZZ")';
        ADOCommand1.Execute;
      except on E: Exception do
        ShowMessage(E.Message);
      end;
    
      Button4.Click;
    end;
    
    //更新
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      ADOCommand1.CommandText := 'UPDATE country SET Area=123,Population=456 WHERE Name="AAA"';
      ADOCommand1.Execute;
    
      ADOCommand1.CommandText := 'UPDATE country SET Capital="MMM" WHERE Capital="YYY"';
      ADOCommand1.Execute;
    
      Button4.Click;
    end;
    
    //删除
    procedure TForm1.Button3Click(Sender: TObject);
    begin
      ADOCommand1.CommandText := 'DELETE * From country WHERE Name="AAA"';
      ADOCommand1.Execute;
      ADOCommand1.CommandText := 'DELETE * From country WHERE Name="XXX"';
      ADOCommand1.Execute;
    
      Button4.Click;
    end;
    
    //查看
    procedure TForm1.Button4Click(Sender: TObject);
    begin
      with ADODataSet1 do begin
        Close;
        CommandText := 'SELECT * FROM country';
        Open;
      end;
    end;
    
    procedure TForm1.FormCreate(Sender: TObject);
    var
      mdbFile: string;
    begin
      {因要修改数据库, 特复制了一份}
      mdbFile := mdbFile + 'C:\Temp\dbdemos.mdb';
    
      ADOConnection1.ConnectionString :=
      'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + mdbFile + ';Persist Security Info=False';
    
      ADOConnection1.LoginPrompt := False;
      ADOConnection1.Open; //ADOConnection1.Connected := True;
    
      ADODataSet1.Connection := ADOConnection1;
      ADOCommand1.Connection := ADOConnection1;
    
      DBGrid1.DataSource := DataSource1;
      DataSource1.DataSet := ADODataSet1;
    end;
    
    end.
    
  • 相关阅读:
    VpnService
    css样式占位和不占位隐藏元素的方法
    apply和call用法
    根据条件改变表格内容
    bootstrap中给表格设置display之后表格宽度变小问题解决
    根据条件决定是否为input设置只读属性
    根据条件决定My97DatePicker日期控件弹出的日期格式
    关于关闭TAB,IFRAME占用的内存不能释放问题
    jquery中attr和prop的区别分析
    jQuery height()、innerHeight()、outerHeight()函数的区别详解
  • 原文地址:https://www.cnblogs.com/del/p/1491506.html
Copyright © 2011-2022 走看看