Developing with Delphi small programs, previously used the Access database, but because Access depends on the office, feeling a little less convenient, look at Delphi using SQLite3.
SQLite is a lightweight database is ACID compliance relational database management system, which is contained in a relatively small C library.
Download SQLite
Official website download page https://www.sqlite.org/download.html
Find the next chart content, according to their own development environment option to download the 32-bit or 64-bit dll dll, tools can be connected to a SQLite3 tool.
Delphi simple SQLite
With the tools to create a database EtTest.db, inside a table User (two field Id and name), made in the root directory of E.
- Under the program into the corresponding directory dll, dll version must correspond to the environment and development .
- Select both controls TSQLConnection and TSQLQuery.
- Configuring TSQLConnection
(1) placed TSQLConnection controls, Name is SQLConnection1.
(2) as set SQLConnection1.ConnectionName SQLITECONNECTION.
(3) to set SQLConnection1.Driver Sqlite
set (4) SQLConnection1.Params the Database for the E: \ EtTest.db (according to your actual situation) point [OK] - Configuring TSQLQuery, put TSQLQuery controls, Name is SQLQuery1.
SQLQuery1.SQLConnection select SQLConnection1. - Two simple operation, add and query
(1) inquiryprocedure TForm1.SearchClick(Sender: TObject); begin SQLConnection1.Connected := True; SQLQuery1.Close; SQLQuery1.SQL.Clear; SQLQuery1.SQL.Add('select id,name from user;'); SQLQuery1.Open; while Not SQLQuery1.Eof do begin Memo1.Lines.Add(SQLQuery1.FieldByName('id').AsString + ' ' + SQLQuery1.FieldByName('name').AsString) ; SQLQuery1.Next; end; end;
(2) Add
procedure TForm1.AddClick(Sender: TObject);
begin
SQLConnection1.Connected := True;
SQLQuery1.Close;
SQLQuery1.SQL.Clear;
SQLQuery1.SQL.Add('insert into user(name) values(' + QuotedStr('李四')+ ');');
SQLQuery1.ExecSQL;
end;