/// <summary> /// 使用 SqlDataAdapter 存取資料庫 /// </summary> public DataSet Excute(string sql, CommandType commandType, SqlParameter[] parameters) { DataSet ds; 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 { ds = _driver.Excute(); } 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(ds); }