/// <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();
}
}
}</code></pre>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
C# SQLite通用读写操作方法
未经允许不得转载:工具盒子 » C# SQLite通用读写操作方法