主题:怎样才能快速将数字1到1千万录入到数据表并显示出来
我想将1千万个数字录入到一个数据表中,希望象各种彩票软件对号码排序那样。我用delphi的database desktop编写了一个数据表,有两个字段a,b分别是i型和a型,然后用bed administor建立好数据库引,再编了以下代码,可用了十分钟左右才录入不到十万个,而彩票软件只要不到一分钟时间,他们是怎么做到的,我错在哪呢。
unit shiyan;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBTables, Grids, DBGrids, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Query1: TQuery;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
s:tstringlist;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);//通过tstringlist变量录入1千万个数据给数据表并显示
var i:integer;
begin
with query1 do
begin
for i:= 0 to s.Count-1 do
begin
close;
sql.Clear;
sql.Add('insert into aa values(:a,:b)');
params[0].asinteger:=i;
params[1].AsString:=s[i];
execsql;
end;
end;
with query1 do
begin
close;
sql.Clear;
sql.Add('select * from aa');
open;
end;
s.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);//删除数据表中的数据
begin
with query1 do
begin
close;
sql.Clear;
sql.Add('delete from aa ');
execsql;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);//将1千万个数赋给tstringlist变量
var f:integer;d:string;
begin
s:=tstringlist.Create;
for f:=1 to 10000000 do
begin
d:=inttostr(f);
s.Add(d);
end;
end;
end.