uniGUI之FDQuery(28)

1]基本设置FDQuery1.Connection
2]执行查询SQL语句
3]执行 非查询SQL语句
4]返回所有数据 和所有 列名


1]基本设置FDQuery1.Connection

 一定要 放一个  FDPhysSQLiteDriverLink1到ServerModule上

 

// uses FireDAC.Phys.SQLite 之后, 可不用添加 TFDPhysSQLiteDriverLink           //访问SQLite  文件数据库

 

  FDQuery1.Connection := UniMainModule.FDConnection1;

  UniMainModule.FDConnection1.LoginPrompt := false; // 取消登录提示框
  UniMainModule.FDConnection1.Open('DriverID=SQLite;Database=test1.Sqlite3');

2]执行查询SQL语句

FDQuery1.Open('select id,name,info from atb');

3]执行 非查询SQL语句

FDQuery1.ExecSQL('INSERT INTO atb VALUES( (select max(id)+1 from atb),''aName'',''aInfo'')');


4]返回所有数据 和所有 列名

   procedure UniDBGridToHTML(aFDquery :TFDQuery;aHTMLFileName:string);
var
  aHTMLtext: TstringList;
   j: integer;
begin
  aHTMLtext := TstringList.Create;
  aHTMLtext.Add
    ('  ' +
    '            ' +
    '    ' +
    ' ');

  aHTMLtext.Add(' ');
    for j := 1to aFDquery.FieldCount dobegin
      aHTMLtext.Add('');
    end;
  aHTMLtext.Add(' ');

  aFDquery.First;
  whilenot(aFDquery.Eof) dobegin
    aHTMLtext.Add(' ');

    for j := 1to aFDquery.FieldCount dobegin
      aHTMLtext.Add('');
    end;
    aHTMLtext.Add(' ');

    aFDquery.Next;
  end;

  aHTMLtext.Add('
'); aHTMLtext.Add(aFDquery.Fields.FieldByNumber(j).FieldName); // 列 名 aHTMLtext.Add('
'); aHTMLtext.Add(aFDquery.Fields.FieldByNumber(j).AsString); // 所有 值 aHTMLtext.Add('
'); aHTMLtext.SaveToFile(aHTMLFileName); aHTMLtext.Free; end;
procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  UniDBGridToHTML(FDquery1,'aa.html');//调用
end;

你可能感兴趣的:(uniGUI之FDQuery(28))