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

            try
            {
                Connection.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    MealSystem _obj = new MealSystem();
                    _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);
        }
Exemplo n.º 2
0
        public DAL.MealSystem GetByID(int ID)
        {
            SqlConnection Connection = DBGate.GetConnection();
            string        SelectByID = "Select  *  from MealSystem  where  ID = @ID ";
            SqlCommand    cmd        = new SqlCommand(SelectByID, Connection);

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

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