Example #1
0
        // add
        public void add(Department bean)
        {
            string sql = "insert into department(dept_name) values(@dept_name)";
            OleDbConnection con = getCon(null);
            OleDbCommand cmd = new OleDbCommand(sql,con);
            OleDbParameter param = new OleDbParameter("@dept_name",bean.Dept_name);
            cmd.Parameters.Add(param);

            cmd.ExecuteNonQuery();

            // close the con
            closeAll(con,cmd,null);
        }
Example #2
0
        // find all
        public List<Department> findAll()
        {
            string sql = "select * from department";
            OleDbConnection con = getCon(null);
            OleDbCommand cmd = new OleDbCommand(sql,con);

            OleDbDataReader reader = cmd.ExecuteReader();
            List<Department> list = new List<Department>();
            while (reader.Read()) {
                Department bean = new Department();

                bean.Id = reader.GetInt32(0);
                bean.Dept_name = reader.GetString(1);

                list.Add(bean);
            }
            if (list.Count() <= 0) {
                return null;
            }

            return list;
        }
Example #3
0
        // load
        public Department load(int id)
        {
            string sql = "select * from department where id=@id";
            OleDbConnection con = getCon(null);
            OleDbCommand cmd = new OleDbCommand(sql, con);
            OleDbParameter param = new OleDbParameter("@id",id);
            cmd.Parameters.Add(param);

            OleDbDataReader reader = cmd.ExecuteReader();
            Department bean = null;
            if (reader.Read()) {
                bean = new Department();

                bean.Id = id;
                bean.Dept_name = reader.GetString(1);

            }

            // close the con
            closeAll(con, cmd, reader);

            return bean;
        }
Example #4
0
        // update
        public void update(Department bean)
        {
            string sql = "update department set dept_name=@dept_name where id=@id";
            OleDbConnection con = getCon(null);
            OleDbCommand cmd = new OleDbCommand(sql,con);
            OleDbParameter[] param = {new OleDbParameter("@dept_name",bean.Dept_name),new OleDbParameter("@id",bean.Id)};
            cmd.Parameters.AddRange(param);

            cmd.ExecuteNonQuery();

            // close the con
            closeAll(con, cmd, null);
        }
Example #5
0
        // search by name
        public Department loadByName(string dept_name)
        {
            string sql = "select * from department where dept_name=@dept_name";
            OleDbConnection con = getCon(null);
            OleDbCommand cmd = new OleDbCommand(sql,con);
            OleDbParameter param = new OleDbParameter("@dept_name",dept_name);
            cmd.Parameters.Add(param);

            OleDbDataReader reader = cmd.ExecuteReader();
            Department bean = null;
            if (reader.Read()) {
                bean = new Department();

                bean.Id = reader.GetInt32(0);
                bean.Dept_name = reader.GetString(1);
            }

            return bean;
        }