UniGUI的SQLite數據庫(04)

1]放FDConnection1和FDQuery1到界面上數據庫

 

 

2]在OnFormCreate事件裏寫ui

FDQuery1.Connection := FDConnection1;
FDConnection1.LoginPrompt:=false; //取消登陸提示框
FDConnection1.Open('DriverID=SQLite;Database=test1.Sqlite3');//test1.Sqlite數據庫要與E:\UniGui_Learn\04OnLineIditom\Win32\Debug\Project1.exe位置一致spa

3]單條數據code

FDQuery1.Open('select id,info from atb where id = 11111 ' );
unimemo1.Text:= FDQuery1.fieldbyname('info').asstring; orm

 

 

4]多條數據blog

FDQuery1.Open(‘select  id,name,info from atb  where 1=1’);//只讀取第一個
unilistbox1.Items.Add( FDQuery1.fieldbyname('name').asstring);
unimemo1.Text:= FDQuery1.fieldbyname('info').asstring; 事件

FDQuery1.next; //第二個到最後一個
while not FDQuery1.eof do begin
unilistbox1.Items.Add( FDQuery1.fieldbyname('name').asstring);
FDQuery1.next;
end;string

 ----------------插入數據------it

 

 

var xzxx:string; maxId:integer;
begin
  FDQuery1.Open('select max(id) as maxId from atb; ');
  maxId:=  FDQuery1.fieldbyname('maxId').AsInteger+1;

    xzxx := stringreplace(uniMemo2.Text, '''', '''''', [rfReplaceAll]); //將 (')-> ('')
    xzxx := stringreplace(xzxx, #13#10, 'Z~z~', [rfReplaceAll]); //將 (^p)-> (Z~z~)
    xzxx := 'insert into atb values('
      + IntToStr(maxId)
      + ',''' + StringReplace(uniedit2.Text, '''', '''''', [rfReplaceAll])
      + ''',''' + xzxx + ''')';

   FDQuery1.ExecSQL(xzxx);

    Caption:=  IntToStr(maxId)+'插入新記錄  成功!' ;
end;

//好像 不能有英文的感嘆號!io

相關文章
相關標籤/搜索