/// <summary>
/// 执行SQL语句,返回影响的记录数
/// </summary>
/// <param name="SQLString">SQL语句</param>
/// <returns>影响的记录数</returns>
public static int ExecuteSql(string SQLString)
{
lock (_lock)
{
using (SQLiteConnection sqliteConn = new SQLiteConnection(sqlConnectionString))
{
sqliteConn.Open();
using (SQLiteCommand cmd = sqliteConn.CreateCommand())
{
try
{
cmd.CommandText = SQLString;
int rows = cmd.ExecuteNonQuery();
return rows;
}
catch (SQLiteException ex)
{
throw ex;
}
finally
{
sqliteConn.Close();
}
}
}
}
}
/// <summary>
/// 执行查询语句,返回DataTable,DataSet的第一张表
/// </summary>
/// <param name="SQLString">查询语句</param>
/// <returns>DataTable</returns>
public static DataTable Query(string SQLString)
{
using (SQLiteConnection sqliteConn = new SQLiteConnection(sqlConnectionString))
{
try
{
sqliteConn.Open();
DataSet ds = new DataSet();
SQLiteDataAdapter sqliteDa = new SQLiteDataAdapter(SQLString, sqliteConn);
sqliteDa.Fill(ds);
return ds.Tables[0];
}
catch (SQLiteException ex)
{
throw ex;
}
finally
{
sqliteConn.Close();
}
}
}