if not FileExists('serdb.sdb') then //判断数据库文件是否存
begin
con1.Params.Add('DriverID=SQLite');//'DriverID=SQLite'之间不能有任何空格
con1.Params.Add('Database=serdb.sdb'); //如果文件存在就打开, 不存在就建立
con1.Params.Add('LockingMod=Exclusive');
con1.Connected:=True;
with fdcmnd1.CommandText do
begin
Add('CREATE TABLE Orders(');
Add('ID integer PRIMARY KEY,'); //Integer 类型, 同时设为主键
Add('Name string(10),'); //能容下 10 个字符的 String 类型
Add('Age byte,'); //Byte 类型
Add('Note text,'); //Memo 类型
Add('Picture blob'); //Blob(二进制)类型
Add(')');
end;
fdcmnd1.Active := True;
end
else
begin
con1.Params.Add('LockingMod=Exclusive');
con1.Open('DriverID=SQLite;Database=serdb.sdb');
end;
fdqry1.Connection := con1;
ds1.DataSet := fdqry1;
dbgrd1.DataSource := ds1;
fdqry1.Open('SELECT * FROM Orders');
参考:http://www.cnblogs.com/del/p/3740170.html
更详尽的请移步至:http://docwiki.embarcadero.com/RADStudio/Berlin/en/Using_SQLite_with_FireDAC