zoukankan      html  css  js  c++  java
  • 学习 SQL 语句 Select(6): 字段运算


    本例效果图:



    代码文件:
    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;
        ADODataSet1: TADODataSet;
        Panel1: TPanel;
        Button1: TButton;
        procedure FormCreate(Sender: TObject);
        procedure Button1Click(Sender: TObject);
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    //计算人均面积, 计算支持 + - * / mod
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      with ADODataSet1 do begin
        Close;
        CommandText := 'SELECT Name, Area / Population AS 人均面积 FROM country';
        Open;
      end;
    end;
    
    procedure TForm1.FormCreate(Sender: TObject);
    var
      mdbFile: string;
    begin
      mdbFile := GetEnvironmentVariable('COMMONPROGRAMFILES');
      mdbFile := mdbFile + '\CodeGear Shared\Data\dbdemos.mdb';
    
      ADODataSet1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' +
        mdbFile + ';Persist Security Info=False';
    
      DBGrid1.DataSource := DataSource1;
      DataSource1.DataSet := ADODataSet1;
    end;
    
    end.
    

    窗体文件:
    object Form1: TForm1
      Left = 0
      Top = 0
      Caption = 'Form1'
      ClientHeight = 407
      ClientWidth = 626
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'Tahoma'
      Font.Style = []
      OldCreateOrder = False
      OnCreate = FormCreate
      PixelsPerInch = 96
      TextHeight = 13
      object DBGrid1: TDBGrid
        Left = 0
        Top = 33
        Width = 626
        Height = 374
        Align = alClient
        DataSource = DataSource1
        TabOrder = 0
        TitleFont.Charset = DEFAULT_CHARSET
        TitleFont.Color = clWindowText
        TitleFont.Height = -11
        TitleFont.Name = 'Tahoma'
        TitleFont.Style = []
      end
      object Panel1: TPanel
        Left = 0
        Top = 0
        Width = 626
        Height = 33
        Align = alTop
        Caption = 'Panel1'
        TabOrder = 1
        object Button1: TButton
          Left = 6
          Top = 5
          Width = 75
          Height = 25
          Caption = 'Button1'
          TabOrder = 0
          OnClick = Button1Click
        end
      end
      object DataSource1: TDataSource
        DataSet = ADODataSet1
        Left = 184
        Top = 112
      end
      object ADODataSet1: TADODataSet
        CursorType = ctStatic
        Parameters = <>
        Left = 232
        Top = 184
      end
    end
    
  • 相关阅读:
    Introduces the basic structure of Android ActivityManagerService
    创业的本质是资源整合
    android系统的经典文章
    GUI软件框架--窗口服务器
    学习法则:只接收能够体系化的知识
    编程思想:以什么样的方式来建模、分析、思考、解决问题
    怎么从本质上理解面向对象的编程思想?
    视图的对象化描述
    DOM= Document Object Model,文档对象模型---以对象管理组织(OMG)的规约为基础的
    GUI(UI编程)语言与面向对象、dsl
  • 原文地址:https://www.cnblogs.com/del/p/1491355.html
Copyright © 2011-2022 走看看