zoukankan      html  css  js  c++  java
  • 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.
    好的代码像粥一样,都是用时间熬出来的
  • 相关阅读:
    MacOS更改zsh命令行前缀
    python中os._exit()和sys.exit(), exit(0)和exit(1) 的用法和区别
    如何解析 redis 的 rdb 文件
    流量回放工具<二>
    策略路由配置<一>
    h3c镜像模式配置
    python上传gz文件请求
    优先队列(大顶堆实现)
    bm和kmp和bf
    dedecms 软件下载模块加入flashget快车下载代码
  • 原文地址:https://www.cnblogs.com/jijm123/p/13417869.html
Copyright © 2011-2022 走看看