public DataTable ExecuteSqlDt(string strSql) //执行SQL
{
DbConnection connection = _db.CreateConnection();
DataTable dt = null;
try
{
connection.Open();
DbCommand cmd = _db.GetSqlStringCommand(strSql);
cmd.Connection = connection;
cmd.CommandType = CommandType.Text;
cmd.CommandText = strSql;
IDataReader dataReader = _db.ExecuteReader(cmd);
dt = new DataTable();
dt.Load(dataReader);
}
catch (Exception ex)
{
_log.Warn("执行sql失败", ex);
throw;
}
finally
{
if (connection != null) connection.Close();
}
return dt;
}
public bool ExecuteSql(string strSql)//执行SQL 有更新或者插入删除时 需做commit Oracle
{
bool result = false;
int effRows = 0;
DbConnection connection = _db.CreateConnection();
DbTransaction transaction = null;
try
{
connection.Open();
transaction = connection.BeginTransaction();
DbCommand cmd = _db.GetSqlStringCommand(strSql);
cmd.Connection = connection;
cmd.CommandType = CommandType.Text;
cmd.Transaction = transaction;
cmd.CommandText = strSql;
effRows = cmd.ExecuteNonQuery();
transaction.Commit();
if (effRows > 0 || effRows == -1)
{
result = true;
}
}
catch (Exception ex)
{
if (transaction != null)
transaction.Rollback();
_log.Warn("执行sql失败", ex);
throw;
}
finally
{
if (connection != null) connection.Close();
}
return result;
}