paradox数据库的创建与数据操作

paradox数据库是delphi自带的.db数据库文件,所在目录即是数据库,一个表是一个.db文件

paradox数据类型简表:

 

 用Ttable创建paradox数据库

复制代码
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,sql语句创建paradox数据库
复制代码
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数据表插入数据:
复制代码
begin
tbl1.DatabaseName:=ExtractFilePath(Application.ExeName)+'db';
tbl1.TableType:=ttParadox;
tbl1.TableName:='User';
tbl1.Close;
tbl1.Open;
while not tbl1.Eof do
tbl1.Delete; //删除原有的数据
for i:=1 to 20 do begin
tbl1.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;
复制代码

append用法:

复制代码
type
  TForm1 = class(TForm)
    Table1: TTable;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  with Table1 do
  begin
    Active := False;
    DatabaseName := '';
    TableType := ttParadox;
    TableName := 'DOCTORINF23.db';
    if not Table1.Exists then begin
       with FieldDefs do begin
          Clear;
          with AddFieldDef do begin
              Name := '姓名';
              DataType := ftString;
              Required := True;
              Size := 10;
          end;
          with AddFieldDef do begin
               Name := '年龄';
               DataType := ftInteger;
          end;//建立字段定,利用AddFieldDef方法添加一个新的TFieldDef对象
          with AddFieldDef do begin
              Name := '职称';
              DataType := ftString;
              Required := True;
              Size := 10;
          end;
       end;
       with IndexDefs do begin
            Clear;
            with AddIndexDef do begin
            Name := 'MYINDEX';
            Fields := '姓名';
            Options := [ixPrimary];
            end;
       end;  //建立索引
       CreateTable;
    end;

  end;
    Table1.Open;
    Table1.Edit;
    Table1.FieldByName('姓名').AsString:='刘延';
    Table1.FieldByName('年龄').AsInteger:=22 ;
    Table1.FieldByName('职称').AsString:='医师';
    //---添加了一条记录 ,append开始添加第二条记录
    Table1.Append;
    Table1.Edit;
    Table1.FieldByName('姓名').AsString:='杨晓';
    Table1.FieldByName('年龄').AsInteger:=25 ;
    Table1.FieldByName('职称').AsString:='医师';
    DBGrid1.DataSource:=DataSource1;
    Table1.Active :=True;
end;

end.
复制代码

 

posted on   癫狂编程  阅读(1252)  评论(0编辑  收藏  举报

编辑推荐:
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
阅读排行:
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
历史上的今天:
2019-08-02 Delphi- ini文件的读写操作

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
好的代码像粥一样,都是用时间熬出来的
点击右上角即可分享
微信分享提示