Пример #1
0
        public INTCategory GetOne(int ID)
        {
            SqlConnection Con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Con"].ToString());

            Con.Open();
            SqlCommand    cmd    = null;
            SqlDataReader SDR    = null;
            INTCategory   ObjTmp = new INTCategory();

            try
            {
                string Query = "SELECT * FROM  INTCategory where CatID=@CatID";
                cmd = new SqlCommand(Query, Con);
                cmd.Parameters.AddWithValue("@CatID", ID);
                SDR = cmd.ExecuteReader();
                while (SDR.Read())
                {
                    ObjTmp.CatID = SDR.GetInt32(0);
                    ObjTmp.Name  = SDR.GetString(1);
                }
            }
            catch (System.Exception e)
            { e.ToString(); }

            finally { Con.Close(); }

            return(ObjTmp);
        }
Пример #2
0
        public static List <INTCategory> GetAll()
        {
            DBCon              con        = new DBCon();
            SqlCommand         cmd        = null;
            SqlDataReader      SDR        = null;
            List <INTCategory> listintcat = new List <INTCategory>();

            try
            {
                string Quary = "Select * from INTCategory ORDER BY CatID DESC";
                cmd = new SqlCommand(Quary, con.Con);
                SDR = cmd.ExecuteReader();

                while (SDR.Read())
                {
                    INTCategory OBJINT = new INTCategory();
                    OBJINT.CatID = SDR.GetInt32(0);
                    OBJINT.Name  = SDR.GetString(1);
                    listintcat.Add(OBJINT);
                }
            }
            catch (Exception e) { e.ToString(); }
            finally { cmd.Dispose(); con.Con.Close(); }
            return(listintcat);
        }