加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

fpc : lazarus SQLite3

发布时间:2020-12-12 19:38:36 所属栏目:百科 来源:网络整理
导读:from http://wiki.lazarus.freepascal.org/SQLdb_Tutorial1/zh_CN SQLdb :: TSQLite3Connection 连接 Sqlite3 在组件面板的SQLdb控件页拖拉一个TSQLite3Connection,一个 TSQLTransaction 和一个 TSQLQuery 控件到窗体。 组件连接关系(Link the components)

from http://wiki.lazarus.freepascal.org/SQLdb_Tutorial1/zh_CN

SQLdb :: TSQLite3Connection 连接 Sqlite3

在组件面板的SQLdb控件页拖拉一个TSQLite3Connection,一个 TSQLTransaction 和一个 TSQLQuery 控件到窗体。

组件连接关系(Link the components)

连接组件:如果使用对象检查器是非常简单的,也可以使用代码来实现。

1. 设置 SQLite3Connection1 的 'Transaction' 属性指向 'SQLTransaction1',

2. 设置SQLTransaction1 的 'Database' 属性自动变更为 'SQLite3Connection1';DatabaseName: 填写test.db

3. 设置 SQLQuery1 的 'Database' 属性指向 'SQLite3Connection1',Lazarus 会自动添加 'Transaction' 属性值;

4. 设置 Datasource1 的 'Dataset' 属性指向 'SQLQuery1';

5. 设置 DBGrid1 的 'Datasource' 属性指向 'Datasource1'

如果你装了Python 2.7,那么 sqlite3.dll 就在Python27DLLs ;
将 sqlite3.dll copy to 你的project 目录下 .

贴代码片段

procedure TForm1.Button1Click(Sender: TObject);
var
  code,sh,city: String;
begin
  code := MaskEdit1.Text;
  sh := copy(code,1,2)+'0000';
  city := copy(code,4)+'00';
  try
    SQLQuery1.Close;
    SQLQuery1.SQL.Clear;
    SQLQuery1.SQL.Add('select code as 区划编码,cname as 地名 from table ');
    SQLQuery1.SQL.Add('where code in (:sh,:city,:code)');
    SQLQuery1.SQL.Add('order by code');
    SQLQuery1.Params.ParamByName('code').AsString := code;
    SQLQuery1.Params.ParamByName('sh').AsString := sh;
    SQLQuery1.Params.ParamByName('city').AsString := city;
    SQLite3Connection1.Connected:= True;
    SQLTransaction1.Active:= True;
    SQLQuery1.Open;
  except
    StatusBar1.SimpleText := '连接数据库 Sqlite3 出错.';
  end;
end;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读