以VS2005为例
1、sqlite.ADO.NET,是专为C#封装的sqlite函数。可以直接安装sqlite.ADO.NET,也可仅仅从中获得System.Data.SQLite.DLL。
2、在c#工程中,选择:项目/添加引用(Add Reference)。若安装了sqlite.ADO.NET,则可直接选择System.Data.SQLite;若没安装,则从“浏览”中找到System.Data.SQLite.DLL文件,确定即可。
3、在工程中添加using System.Data.SQLite,会自动补全。
完成以上步骤,即可使用sqlite了。
应用示例:
//连接数据库
SQLiteConnection connsqlite = new SQLiteConnection();
string strConnect = "Data Source=" + filename; //filename为数据库文件名
connsqlite.ConnectionString = strConnect;
connsqlite.Open(); //打开数据库
//断开数据库
connsqlite.Close(); //关闭数据库
//数据库插入
string sql = "insert into table1 values('id','name')";
SQLiteCommand cmd = new SQLiteCommand(sql, connsqlite);
cmd.ExecuteNonQuery();
//数据库查询
string sql = "select id,name from table1";
SQLiteCommand cmd = new SQLiteCommand(sql, connsqlite);
SQLiteDataReader DataReader = cmd.ExecuteReader(); //DataReader中即为查询结果
cmd.Dispose(); //释放资源