Paradox数据库介绍:
是delphi中自带的.db文件式数据库,目录即是数据库名,一个文件是一个表
用Ttable创建Paradox数据表:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
begin
with Table1 do //页面控件
begin
Active := False;
DatabaseName := '';
TableType := ttParadox;
TableName := 'CustInfo.db';
with FieldDefs do
begin
Clear;
Add('Field1', ftInteger, 0, True);
Add('Field2', ftString, 30, False); //字段名,类型,大小,是否为空
end;
CreateTable;
end;
end;
用Tquery创建paradox数据库:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
procedure TForm1.FormCreate(Sender: TObject);
var
TempQuery:TQuery;
DefField :String;
TableName:String;
CreateSQL:String;
begin
CreateSQL:='Create Table "%s" (%s)';
Deffield := ' Field1 Integer, Field2 CHAR(30) ';
TableName := 'C:\DB01.DB';
TempQuery := TQuery.Create(Application);
with TempQuery do
begin
try
SQL.Text:=Format(CreateSQL,[tableName,deffield]);
ExecSQL;
finally
Free;
end;
end;
end;
为paradox数据库插入数据:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
begintbl1.DatabaseName:=ExtractFilePath(Application.ExeName)+'db'; //目录即是数据库名,一个文件是一个表tbl1.TableType:=ttParadox;tbl1.TableName:='User';tbl1.Close;tbl1.Open;while not tbl1.Eof dotbl1.Delete; //删除原有的数据for i:=1 to 20 do begintbl1.Insert;tbl1.FieldByName('fID').AsInteger:=i;tbl1.FieldByName('fName').AsString:='段改阳'+inttostr(i);tbl1.FieldByName('ftype').AsInteger:=i;tbl1.FieldByName('fdescrip').AsString:='fdescrip段改阳'+inttostr(i);end;tbl1.Post;end;