谢谢yzhshi为我尽力!!
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids, DBGrids, Db, DBTables, ExtCtrls, DBCtrls;
type
TForm1 = class(TForm)
DataSource1: TDataSource;
Query1: TQuery;
DBGrid1: TDBGrid;
Button1: TButton;
DBNavigator1: TDBNavigator;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
VAR
J:INTEGER;
begin //生成数据表
query1.sql.clear;
query1.SQL.add('create table tb3');
query1.SQL.add('(c0 int,');
query1.SQL.add('c1 int,');
query1.SQL.add('c2 int,');
query1.SQL.add('c3 int)');
query1.execsql;
FOR J:=0 TO 5 DO
BEGIN
query1.sql.clear;
query1.sql.add('insert into tb3 values
a0,:a1,:a2,:a3)');
query1.parambyname('a0').asinteger:=1+J;
query1.parambyname('a1').asinteger:=2+J;
query1.parambyname('a2').asinteger:=3+J;
query1.parambyname('a3').asinteger:=4+J;
query1.execsql;
END;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
query1.sql.clear;
query1.sql.add('select * from tb3');
query1.Open; //查看
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
query1.SQL.Clear;
query1.SQL.add('insert into tb3 select sum(c0),sum(c1),sum(c2),sum(c3)');
query1.SQL.add('from tb3');
query1.execsql; //合计插入
end;
end.