• 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.
    好的代码像粥一样,都是用时间熬出来的
  • 相关阅读:
    形形色色的软件生命周期模型(1)——瀑布型、增量型
    TestNG系列之三:TestNG忽略测试
    TestNG系列之二:TestNG套件测试
    TestNG系列之:TestNG基本注解(注释)
    testng的xml文件说明(TestNG DTD)
    testng参数化(提供测试数据)
    TestNG 八 并发测试
    TestNG 七 annotation
    TestNG 六 测试结果
    TestNG 五 运行TestNG
  • 原文地址:https://www.cnblogs.com/jijm123/p/13417869.html
Copyright © 2020-2023  润新知