Example #1
0
        public List <AmenitiesType> GetAll()
        {
            SqlConnection        Connection = DBGate.GetConnection();
            string               SelectAll  = " select * from AmenitiesType ";
            SqlCommand           cmd        = new SqlCommand(SelectAll, Connection);
            List <AmenitiesType> lst        = new List <AmenitiesType>();

            try
            {
                Connection.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    AmenitiesType _obj = new AmenitiesType();
                    _obj.ID   = int.Parse(reader["ID"].ToString());
                    _obj.Name = reader["AmenitiesName"].ToString();
                    lst.Add(_obj);
                }
            }
            catch (SqlException ex)
            {
                frmDone frmerror = new frmDone(ex.ToString());
                frmerror.ShowDialog();
            }
            finally { Connection.Close(); }
            return(lst);
        }
Example #2
0
        public DAL.AmenitiesType GetByID(int ID)
        {
            SqlConnection Connection = DBGate.GetConnection();
            string        SelectByID = "Select  *  from AmenitiesType  where  ID = @ID ";
            SqlCommand    cmd        = new SqlCommand(SelectByID, Connection);

            cmd.Parameters.AddWithValue("@ID", ID);
            AmenitiesType _obj = new AmenitiesType();

            try
            {
                Connection.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                if (reader.Read())
                {
                    _obj.ID   = int.Parse(reader["ID"].ToString());
                    _obj.Name = reader["Name"].ToString();
                }
            }
            catch (SqlException ex)
            {
                frmDone frmerror = new frmDone(ex.ToString());
                frmerror.ShowDialog();
            }
            finally
            {
                Connection.Close();
            }
            return(_obj);
        }