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

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

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

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