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

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

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

            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);
        }