예제 #1
0
        public DAL.AmenitiesOfUnits GetByUnitIDandAmenitiesID(int _UnitID, int _AmenitiesID)
        {
            SqlConnection Connection = DBGate.GetConnection();
            string        SelectByID = "Select  *  from AmenitiesOfUnits  where UnitID =@UnitID and AmenitiesID=@AmenitiesID ";
            SqlCommand    cmd        = new SqlCommand(SelectByID, Connection);

            cmd.Parameters.AddWithValue("@UnitID", _UnitID);
            cmd.Parameters.AddWithValue("@AmenitiesID", _AmenitiesID);
            AmenitiesOfUnits _obj = new AmenitiesOfUnits();

            try
            {
                Connection.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                if (reader.Read())
                {
                    _obj.ID          = int.Parse(reader["ID"].ToString());
                    _obj.UnitID      = int.Parse(reader["UnitID"].ToString());
                    _obj.AmenitiesID = int.Parse(reader["AmenitiesID"].ToString());
                }
            }
            catch (SqlException ex)
            {
                frmDone frmerror = new frmDone(ex.ToString());
                frmerror.ShowDialog();
            }
            finally
            {
                Connection.Close();
            }
            return(_obj);
        }
예제 #2
0
        public List <AmenitiesOfUnits> GetAllByAmenitiesID(int _AmenitiesID)
        {
            SqlConnection Connection = DBGate.GetConnection();
            string        SelectAll  = " select * from AmenitiesOfUnits  where AmenitiesID = @AmenitiesID ";
            SqlCommand    cmd        = new SqlCommand(SelectAll, Connection);

            cmd.Parameters.AddWithValue("@AmenitiesID", _AmenitiesID);
            List <AmenitiesOfUnits> lst = new List <AmenitiesOfUnits>();

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