コード例 #1
0
        //Call to Update Payroll data in the server database
        public void UpdateRoles(RoleDO update)
        {
            //Try(catch) to open a connection and access the server database
            try
            {
                using (SqlConnection sqlConnect = new SqlConnection(connectionString))
                    using (SqlCommand sqlCommand = new SqlCommand("UPDATE_ROLE", sqlConnect))
                    {
                        sqlCommand.CommandType = CommandType.StoredProcedure;
                        sqlConnect.Open();

                        sqlCommand.Parameters.AddWithValue("@RoleID", update.RoleID);
                        sqlCommand.Parameters.AddWithValue("@RoleName", update.RoleName);
                        sqlCommand.Parameters.AddWithValue("@RoleDescription", update.RoleDescription);

                        sqlCommand.ExecuteNonQuery();
                    }
            }
            catch (Exception error)
            {
                Logger Error = new Logger();
                Error.logErrors(error);
            }
            finally { }
        }
コード例 #2
0
        //------------------------------------------------------------------------------------------------------------------------------------------------------//

        public List <RoleDO> RoleList()
        {
            List <RoleDO> roleList = new List <RoleDO>();

            //Try(catch) to open a connection and access the server database
            try
            {
                using (SqlConnection sqlConnect = new SqlConnection(connectionString))
                    using (SqlCommand sqlCommand = new SqlCommand("VIEW_ROLES", sqlConnect))
                    {
                        sqlCommand.CommandType = CommandType.StoredProcedure;
                        sqlConnect.Open();

                        using (SqlDataReader dataReader = sqlCommand.ExecuteReader())
                        {
                            //Reading the data in each column by column name
                            while (dataReader.Read())
                            {
                                //Creates a New List to store the Users in.
                                RoleDO listRole = new RoleDO();
                                listRole.RoleID          = (int)dataReader["RoleID"];
                                listRole.RoleName        = (string)dataReader["RoleName"];
                                listRole.RoleDescription = (string)dataReader["RoleDescription"];

                                roleList.Add(listRole);
                            }
                        }
                    }
            }
            catch (Exception error)
            {
                Logger Error = new Logger();
                Error.logErrors(error);
            }
            finally { }

            return(roleList);
        }