一,引用System.Data.SQLite.dll类库
1,百度云下载连接:http://pan.baidu.com/s/1c1Ozndm
2,项目引用此文件。
二,SQLiteHelp辅助类
using System.Data;
using System.Data.SQLite;
namespace Sqlite
{
public class SQLiteHelper
{
public SQLiteConnection conn;
public SQLiteHelper(string connStr)
{
conn = new SQLiteConnection(connStr);
}
public SQLiteHelper()
{
[conn=...;]
}
public DataSet Query(string sql, params SQLiteParameter[] parameters)
{
DataSet ds = new DataSet();
using (conn)
{
using (SQLiteCommand comm = new SQLiteCommand(sql, conn))
{
if (parameters != null)
{
comm.Parameters.AddRange(parameters);
}
using (SQLiteDataAdapter da = new SQLiteDataAdapter(comm))
{
da.Fill(ds);
}
}
}
return ds;
}
public bool ExcuteNonQuery(string sql, params SQLiteParameter[] parameters)
{
int row;
using (conn)
{
conn.Open();
using (SQLiteTransaction transaction = conn.BeginTransaction())
{
using (SQLiteCommand comm = new SQLiteCommand(sql, conn))
{
if (parameters != null)
{
comm.Parameters.AddRange(parameters);
}
row = comm.ExecuteNonQuery();
}
transaction.Commit();
}
}
return row > 0;
}
public SQLiteDataReader ExcuteDataReader(string sql, params SQLiteParameter[] parameters)
{
using (SQLiteCommand comm = new SQLiteCommand(sql, conn))
{
if (parameters != null)
{
comm.Parameters.AddRange(parameters);
}
conn.Open();
return comm.ExecuteReader(CommandBehavior.CloseConnection);
}
}
}
}