标签:style class c tar ext color
{建立} procedure TForm1.FormCreate(Sender: TObject); const dbPath = ‘C:\Temp\SQLiteTest.sdb‘; strTable = ‘CREATE TABLE MyTable(Id integer PRIMARY KEY AUTOINCREMENT, Name string(10), Age byte)‘; //Id, Name, Age 三个字段 //integer PRIMARY KEY AUTOINCREMENT: 自增字段 begin if FileExists(dbPath) then DeleteFile(dbPath); FDConnection1.ConnectionString := ‘DriverID=SQLite; Database=‘ + dbPath; FDConnection1.ExecSQL(strTable); FDQuery1.Open(‘SELECT * FROM MyTable‘); end; {插入} procedure TForm1.Button1Click(Sender: TObject); const strInsert = ‘INSERT INTO MyTable(Name, Age) VALUES(:name, :age)‘; begin FDConnection1.ExecSQL(strInsert, [‘AAA‘, 11]); FDConnection1.ExecSQL(strInsert, [‘BBB‘, 22]); FDConnection1.ExecSQL(strInsert, [‘CCC‘, 33]); FDConnection1.ExecSQL(strInsert, [‘DDD‘, 44]); FDConnection1.ExecSQL(strInsert, [‘EEE‘, 55]); FDQuery1.Refresh; end; {更新} procedure TForm1.Button2Click(Sender: TObject); begin FDConnection1.ExecSQL(‘UPDATE MyTable SET Age=:a WHERE Name=:n‘, [Random(100), ‘AAA‘]); FDQuery1.Refresh; end; {删除} procedure TForm1.Button3Click(Sender: TObject); begin FDConnection1.ExecSQL(‘DELETE FROM MyTable WHERE Age>33‘); FDQuery1.Refresh; end; {查询符合条件的第一个结果} procedure TForm1.Button4Click(Sender: TObject); var V: Variant; begin V := FDConnection1.ExecSQLScalar(‘SELECT Age FROM MyTable WHERE Name = :x‘, [‘BBB‘]); ShowMessage(V); end;
FireDAC 下的 Sqlite [5] - 数据的插入、更新、删除,布布扣,bubuko.com
FireDAC 下的 Sqlite [5] - 数据的插入、更新、删除
标签:style class c tar ext color
原文地址:http://www.cnblogs.com/del/p/3742423.html