/// /// sqlite資料庫簡單操作的分裝(sqlite3)
/// 注意:sqlite 是不區分大小寫
///
public class dbaccess
public dbaccess ()
/// /// 資料庫鏈結
///
///
public void opendb (string connectionstring)
catch(exception e)
} /// /// 關閉資料庫
///
public void closesqlconnection ()
dbcommand = null;
if (reader != null)
reader = null;
if (dbconnection != null)
dbconnection = null;
("disconnected from db.關閉資料庫!");
}/// /// sql資料庫命令
///
///
/// 執行結果
public sqlitedatareader executequery (string sqlquery)
/// /// 查詢表中全部資料 param tablename=表名
/// select*from 表名
///
public sqlitedatareader readfulltable (string tablename)
/// /// 插入資料 param tablename=表名 values=插入資料內容
/// insert into 表名 values(aa,bb,cc...)
///
public sqlitedatareader insertinto (string tablename, string values)
query += ")";
return executequery (query);
}/// /// 更新資料 param tablename=表名 cols=更新字段 colsvalues=更新內容 selectkey=查詢字段(主鍵) selectvalue=查詢內容
/// update 表名 set 欄位1 = ***,欄位2 = *** where 主鍵 = yyy
///
public sqlitedatareader updateinto (string tablename, string cols,string colsvalues,string selectkey,string selectvalue)
query += " where "+selectkey+" = "+selectvalue+" ";
return executequery (query); }
/// /// 刪除資料 param tablename=表名 cols=字段 colsvalues=內容
/// delete from 表名 where 欄位1 = *** or 欄位2 = yyy
///
public sqlitedatareader delete(string tablename,string cols,string colsvalues)
return executequery (query); }
/// /// 插入資料 param tablename=表名 cols=插入字段 value=插入內容
/// insert into 表名 (欄位1,欄位2...) values (***,yyy...)
///
public sqlitedatareader insertintospecific (string tablename, string cols, string values)
string query = "insert into " + tablename + "(" + cols[0];
for (int i = 1; i < cols.length; ++i)
query += ") values (" + values[0];
for (int i = 1; i < values.length; ++i)
query += ")";
return executequery (query);
} /// /// 刪除表中全部資料
/// delete from 表名
///
public sqlitedatareader deletecontents (string tablename)
/// /// 建立表 param name=表名 col=欄位名 coltype=字段型別
/// create table 表名(欄位1 字段型別1,欄位2 字段型別2,...)
/// 不設定主鍵,讓資料庫自己設定隱藏主鍵
///
public sqlitedatareader createtable (string name, string col, string coltype)
string query = "create table " + name + " (" + col[0] + " " + coltype[0];
for (int i = 1; i < col.length; ++i)
query += ")";
return executequery (query);
} /// /// 按條件查詢資料 param tablename=表名 items=查詢字段 col=查詢字段 operation=運算子 values=內容
/// select 欄位1,欄位2,... from 表名 where 欄位x=<> '***' and 欄位y=<> 'yyy' ...
///
public sqlitedatareader selectwhere (string tablename, string items, string col, string operation, string values)
string query = "select " + items[0];
for (int i = 1; i < items.length; ++i)
query += " from " + tablename + " where " + col[0] + operation[0] + "'" + values[0] + "' ";
for (int i = 1; i < col.length; ++i)
return executequery (query);
} /// /// 查詢表
/// select * from 表名 where 字段 = ***
///
public sqlitedatareader select(string tablename, string col, string values)
/// /// 查詢表
/// select * from 表名 where 字段=<> ***
///
public sqlitedatareader select(string tablename, string col,string operation, string values)
/// /// 公升序查詢
/// select * from 表名 order by 字段 asc
///
public sqlitedatareader selectorderasc (string tablename,string col)
/// /// 降序查詢
/// select * from 表名 order by 字段 desc
///
public sqlitedatareader selectorderdesc (string tablename,string col)
/// /// 查詢錶行數
/// select count(*) from 表名
///
public sqlitedatareader selectcount(string tablename)
}
在linux下使用sqlite
資料匯入的 可以是其他應用程式的輸出,也可以是指定的文字檔案,這裡採用指定的文字檔案。1.首先,確定匯入的資料來源,這裡是待匯入的,按固定格式的文字檔案。2.然後,依照匯入的檔案格式,確定想匯入的目標資料表,這個資料表如果沒有,可以依照待匯入的文字檔案格式,建立乙個相對應的資料表。3.最後,執行.i...
SQLite在VC下的使用
一 sqlite簡介 sqlite 是用c語言編寫的開源資料庫,主要用於嵌入式,你也可以把它整合在自己的桌面程式中,也有人將其替代access,用作後台資料庫。sqlite 支援多數sql92標準,例如 索引 限制 觸發和檢視支援。支援 null integer real text 和 blob 資...
SQLite在VC下的使用
一 sqlite簡介 sqlite 是用c語言編寫的開源資料庫,主要用於嵌入式,你也可以把它整合在自己的桌面程式中,也有人將其替代access,用作後台資料庫。sqlite 支援多數sql92標準,例如 索引 限制 觸發和檢視支援。支援 null integer real text 和 blob 資...