Exemplo n.º 1
0
        public clsQuocGia GetById(int id)
        {
            try
            {
                clsQuocGia obj = new clsQuocGia();
                string str = "select * from tblQuocGia where id=@id order by stt";
                SqlCommand com = new SqlCommand(str, con.getCon());
                com.Parameters.AddWithValue("@id", id);
                con.openCon();
                SqlDataReader dr = com.ExecuteReader();
                if (dr.Read())
                {
                    obj.Id = id;
                    if (dr["TenQuocGia"] != DBNull.Value)
                    {
                        obj.TenQuocGia = dr["TenQuocGia"].ToString();
                    }
                    if (dr["stt"] != DBNull.Value)
                    {
                        obj.Stt = Convert.ToInt32(dr["stt"].ToString());
                    }
                }
                return obj;
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                con.closeCon();
            }
        }
Exemplo n.º 2
0
        public List<clsQuocGia> GetAll()
        {
            try
            {
                List<clsQuocGia> list = new List<clsQuocGia>();
                string str = "select * from tblQuocGia";
                SqlCommand com = new SqlCommand(str, con.getCon());
                con.openCon();
                SqlDataReader dr = com.ExecuteReader();
                while (dr.Read())
                {
                    clsQuocGia obj = new clsQuocGia();
                    if (dr["tenquocgia"] != DBNull.Value)
                    {
                        obj.TenQuocGia = dr["tenquocgia"].ToString();
                    }
                    if (dr["stt"] != DBNull.Value)
                    {
                        obj.Stt = Convert.ToInt32(dr["stt"].ToString());
                    }
                    if (dr["id"] != DBNull.Value)
                    {
                        obj.Id = Convert.ToInt32(dr["id"].ToString());
                    }
                    list.Add(obj);
                }
                return list;
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                con.closeCon();
            }
        }