/// <summary>
/// 执行语句
/// </summary>
/// <param name="dbPath"></param>
/// <param name="sql"></param>
static void ExecSql(string dbPath, string sql)
{
ExecSql(dbPath, sql, null);
}
/// <summary>
/// 执行语句
/// </summary>
/// <param name="dbPath"></param>
/// <param name="sql"></param>
/// <param name="prams"></param>
static void ExecSql(string dbPath, string sql, SQLiteParameter[] prams)
{
using (SQLiteConnection conn = new SQLiteConnection("Data Source=" + dbPath))
{
conn.Open();
using (SQLiteCommand cmd = new SQLiteCommand(sql, conn))
{
if (prams != null)
{
foreach (SQLiteParameter parameter in prams)
{
cmd.Parameters.Add(parameter);
}
}
cmd.ExecuteNonQuery();
cmd.Dispose();
}
conn.Close();
conn.Dispose();
}
}
/// <summary>
/// 执行查询
/// </summary>
/// <param name="dbPath"></param>
/// <param name="sql"></param>
/// <param name="fn"></param>
static void ReadSql(string dbPath, string sql, Action<SQLiteDataReader> fn)
{
ReadSql(dbPath, sql, fn, null);
}
/// <summary>
/// 执行查询
/// </summary>
/// <param name="dbPath"></param>
/// <param name="sql"></param>
/// <param name="fn"></param>
/// <param name="prams"></param>
static void ReadSql(string dbPath, string sql, Action<SQLiteDataReader> fn, SQLiteParameter[] prams)
{
using (SQLiteConnection conn = new SQLiteConnection("Data Source=" + dbPath))
{
conn.Open();
using (SQLiteCommand cmd = new SQLiteCommand(sql, conn))
{
if (prams != null)
{
foreach (SQLiteParameter parameter in prams)
{
cmd.Parameters.Add(parameter);
}
}
using (SQLiteDataReader rs = cmd.ExecuteReader())
{
while (rs.Read())
{
fn(rs);
}
rs.Close();
rs.Dispose();
}
cmd.Dispose();
}
conn.Close();
conn.Dispose();
}
}
/// 执行语句
/// </summary>
/// <param name="dbPath"></param>
/// <param name="sql"></param>
static void ExecSql(string dbPath, string sql)
{
ExecSql(dbPath, sql, null);
}
/// <summary>
/// 执行语句
/// </summary>
/// <param name="dbPath"></param>
/// <param name="sql"></param>
/// <param name="prams"></param>
static void ExecSql(string dbPath, string sql, SQLiteParameter[] prams)
{
using (SQLiteConnection conn = new SQLiteConnection("Data Source=" + dbPath))
{
conn.Open();
using (SQLiteCommand cmd = new SQLiteCommand(sql, conn))
{
if (prams != null)
{
foreach (SQLiteParameter parameter in prams)
{
cmd.Parameters.Add(parameter);
}
}
cmd.ExecuteNonQuery();
cmd.Dispose();
}
conn.Close();
conn.Dispose();
}
}
/// <summary>
/// 执行查询
/// </summary>
/// <param name="dbPath"></param>
/// <param name="sql"></param>
/// <param name="fn"></param>
static void ReadSql(string dbPath, string sql, Action<SQLiteDataReader> fn)
{
ReadSql(dbPath, sql, fn, null);
}
/// <summary>
/// 执行查询
/// </summary>
/// <param name="dbPath"></param>
/// <param name="sql"></param>
/// <param name="fn"></param>
/// <param name="prams"></param>
static void ReadSql(string dbPath, string sql, Action<SQLiteDataReader> fn, SQLiteParameter[] prams)
{
using (SQLiteConnection conn = new SQLiteConnection("Data Source=" + dbPath))
{
conn.Open();
using (SQLiteCommand cmd = new SQLiteCommand(sql, conn))
{
if (prams != null)
{
foreach (SQLiteParameter parameter in prams)
{
cmd.Parameters.Add(parameter);
}
}
using (SQLiteDataReader rs = cmd.ExecuteReader())
{
while (rs.Read())
{
fn(rs);
}
rs.Close();
rs.Dispose();
}
cmd.Dispose();
}
conn.Close();
conn.Dispose();
}
}