我怎么用不了insert to这个SQL语句。动态创建了一个表1.db(字段a1和a2为smallint),
另外定义整形全局变量a1和a2。随机产生两个整数赋给a1和a2。我想把a1和a2作为字段值
插入到表1.db中,我直接用以下代码,运行后提示:Field 'a1' is of an unknown type.
我想把www.smth.edu.cn论坛上休闲娱乐中的一个清零游戏(用JAVA编的)改为delphi。
这是其中的部分代码。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, db,dbtables, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
table1:tquery;
a1,a2:integer;
procedure fu(var a1,a2:integer);
begin
a1:=a1 mod 4;
a2:=a2 mod 4;
form1.Button1.Caption:=inttostr(a1);
form1.button2.caption:=inttostr(a2);
table1.ExecSQL ;
table1.SQL.Clear ;
table1.SQL.Add('insert into l.db');
table1.SQL.Add('values
a1,:a2)');
table1.ExecSQL ;
end;
procedure Button1Click(Sender: TObject);
begin
table1:=tquery.Create(self);
with table1 do
begin
with sql do
begin
clear;
add('create table "l.db"');
add('(a1 smallint,');
add('a2 smallint)');
end;
end;
randomize;
a1:=trunc(random(4));
a2:=trunc(random(4));
fu(a1,a2);
end;
end.