//Method for creating the SQL statement that retrieves the data displayed by the yearly column chart public static MySqlCommand getMonthlyTotalsCommand(String sqlStatement, QueryData paramContainer) { Guard.notNull(sqlStatement, "SQL statement"); Guard.notNull(paramContainer, "parameter container"); MySqlCommand monthlyTotalsCommand = new MySqlCommand(sqlStatement, DBConnectionManager.getConnection(DBConnectionManager.BUDGET_MANAGER_CONN_STRING));//Nu e neaparata adaugarea conexiunii la crearea comenzii intrucat metoda getData a clasei DBConnectionmanager face deja asta in mod implicit monthlyTotalsCommand.Parameters.AddWithValue("@paramID", paramContainer.UserID); monthlyTotalsCommand.Parameters.AddWithValue("@paramYear", paramContainer.Year); return(monthlyTotalsCommand); }
public static DataTable getData(MySqlCommand command) { //Creates a new connection MySqlConnection conn = DBConnectionManager.getConnection(DBConnectionManager.BUDGET_MANAGER_CONN_STRING); //Assigning the connection to the command object command.Connection = conn; //Creating a DataAdapter based on the command object MySqlDataAdapter adp = DBConnectionManager.getDataAdapter(command); //Creating an empty DataTable DataTable dataTable = new DataTable(); try { //Se deschide conexiunea si se umple cu date obiectul DataTable //Opening the connection and populating the DataTable object with data conn.Open(); adp.Fill(dataTable); } catch (MySqlException ex) { //If an exception is thrown then a MessageBox containing the execption or the custom message (for error code 1042) is displayed int errorCode = ex.Number; String message; if (errorCode == 1042) { message = "Unable to connect to the database! Please check the connection and try again."; } else { message = ex.Message; } MessageBox.Show(message, "DBConnectionManager", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { //Closing the connection irrespective of the command execution result conn.Close(); } return(dataTable); }