//Method for reading specific information on users form the database public List <UserDO> UserDetails(int UserId) { //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 UserDO List <UserDO> user = new List <UserDO>(); //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("USER_READ_BY_ID", scon); //Defining what kind of command our SqlCommand is readRowById.CommandType = CommandType.StoredProcedure; //Adding in all the variables. Format: ("@SqlVariable", C#VariableValue) readRowById.Parameters.AddWithValue("@UserId", UserId); //opening sql connection scon.Open(); //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 user = UserListMap.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(user); }
//Method for reading general information on users from database public List <UserDO> UserReadAll() { //Establishing new list using model UserDO List <UserDO> allUsers = new List <UserDO>(); //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("USER_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 allUsers = UserListMap.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(allUsers); }