Delphi連接SQLite3

11689阅读 4评论2008-10-19 libin1983
分类:

最近在嘗試在Delphi中使用SQLite,昨晚終於找到一個連接SQLite的方法:安裝 SQLite ODBC Driver 在 Delphi中通過ADO組件(TADOQuery, TADOConnection)直接訪問。
步驟:
    1. 下載
    2. 安裝 SQLite ODBC Driver;
    3. 在Delphi工程中添加 TADOQuery, TADOConnection 組件;
    4. 設置 TADOConnection 的ConnectionString;
       設置步驟:
       1)單擊TADOConnection組件 ConectionString變的按鈕, 選擇 "Use Connection String" -> "Build"
       2)彈出的菜單中, 程序選擇: "Microsoft OLE DB Provider for ODBC Drivers"
       3)指定的數據源: 選"使用數據源名稱"->"SQLite3 Datasource"
       4)測試連接是否成功。

    (over)


// 創建表 test

procedure TForm1.Bt_createClick(Sender: TObject);
begin
  try
    if cnnSqlite.Connected=false then cnnSqlite.open;
    if sQry.Active then sQry.Close;
    sQry.SQL.Clear;
    sQry.SQL.Add('create TABLE test (testid INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, title string unique, text text)');
    sQry.ExecSQL;
  finally
    cnnSqlite.Close;
  end;
  showMessage('over');
end;

上一篇:PCC-S-02021, Found newline while scanning string l
下一篇:OpenBSD3.9上安裝python2.5

文章评论