//Method for searching for a player by their name public List <PlayerDO> PlayerReadByName(string winner) { //Defining SqlConnection for this method SqlConnection scon = new SqlConnection(_conn); //Establishing a new data adapter SqlDataAdapter iDReader = null; //Establishing a new data table DataTable table = new DataTable(); //Establishing new list using model PlayerDO List <PlayerDO> player = new List <PlayerDO>(); //Beginning the processes try { //Defining a variable for the SqlCommand, as well as the stored proc and connection we're using SqlCommand readRowById = new SqlCommand("READ_PLAYER_BY_NAME", scon); //Defining what kind of command our SqlCommand is readRowById.CommandType = CommandType.StoredProcedure; //opening sql connection scon.Open(); //Adding in all the variables. Format: ("@SqlVariable", C#VariableValue) readRowById.Parameters.AddWithValue("@Name", winner); //defining our adapter and what command it uses iDReader = new SqlDataAdapter(readRowById); //telling the code to use the stored procedure readRowById.ExecuteNonQuery(); //telling code to use the data table to fill itself iDReader.Fill(table); //setting our list equal to all information pulled from database by running it through a mapper player = PlayerListMap.DataTableToList(table); } //Catch for any errors that may happen catch (Exception ex) { //passing in the exception that was thrown to the errorhandler ErrorHandlerDAL.ErrorLogger(ex); } //finally cleans up any last loose ends finally { //closing SqlConnection scon.Close(); //disposing of the SqlConnection scon.Dispose(); } //Sending all information pulled from the database up to the PL return(player); }
//Method for Reading all general information on all players in the database public List <PlayerDO> PlayerReadAll() { //Establishing new list using model PlayerDO List <PlayerDO> players = new List <PlayerDO>(); //Defining SqlConnection for this method SqlConnection scon = new SqlConnection(_conn); //Establishing a new data adapter SqlDataAdapter adapter = null; //Establishing a new data table DataTable table = new DataTable(); //Beginning the processes try { //Defining a variable for the SqlCommand, as well as the stored proc and connection we're using SqlCommand readRow = new SqlCommand("PLAYER_READ_ALL", scon); //Defining what kind of command our SqlCommand is readRow.CommandType = CommandType.StoredProcedure; //opening sql connection scon.Open(); //defining our adapter and what command it uses adapter = new SqlDataAdapter(readRow); //telling code to use the data table to fill itself adapter.Fill(table); //setting our list equal to all information pulled from database by running it through a mapper players = PlayerListMap.DataTableToList(table); } //Catch for any errors that may happen catch (Exception ex) { //passing in the exception that was thrown to the errorhandler ErrorHandlerDAL.ErrorLogger(ex); } //finally cleans up any last loose ends finally { //closing SqlConnection scon.Close(); //disposing of the SqlConnection scon.Dispose(); } //Sending all information pulled from the database up to the PL return(players); }