/// <summary> /// 使用 ExcuteReader()存取資料庫 /// </summary> public IDataReader ExcuteReader(string sql, CommandType commandType, SqlParameter[] parameters) { IDataReader reader; var conn = _driver.Connection; _driver.Command.CommandText = sql; _driver.Command.Connection = conn; _driver.Command.CommandType = commandType; _driver.Command.CommandTimeout = _driver.TimeOut; if (parameters != null) { foreach (var param in parameters) { _driver.Command.Parameters.Add(param); } ; } try { reader = _driver.ExcuteReader(); } catch (Exception ex) { if (IsOnTransaction()) { _tran.Rollback(); _tran = null; } _driver.Dipose(); throw new Exception($" 執行 {sql} 發生錯誤 | 錯誤原因: " + Environment.NewLine + ex); } finally { _driver.Command.Parameters.Clear(); _driver.Command.Dispose(); } return(reader); }