コード例 #1
0
        public void delete(int idExcursie)
        {
            log.Info("Stergere excursie");
            IDbConnection con = DBUtils.getConnection();

            using (var comm = con.CreateCommand())
            {
                comm.CommandText = "delete from excursie where idExcursie=@idExcursie";
                IDbDataParameter paramId = comm.CreateParameter();
                paramId.ParameterName = "@idExcursie";
                paramId.Value         = idExcursie;
                comm.Parameters.Add(paramId);
                var dataR = comm.ExecuteNonQuery();
                if (dataR == 0)
                {
                    log.Info("Nu a fost stearsa excursia");
                }
                else
                {
                    log.Info("Excursia a fost stearsa");
                }
            }
        }
        public Challenge Save(Challenge challenge)
        {
            log.InfoFormat("Entering Save with Challenge {0}", challenge);
            var con = DBUtils.getConnection();

            using (var comm = con.CreateCommand())
            {
                comm.CommandText = "insert into Challenge(minimum_age,maximum_age,name)  values (@minimum_age , @maximum_age , @name)";

                var paramMinimumAge = comm.CreateParameter();
                paramMinimumAge.ParameterName = "@minimum_age";
                paramMinimumAge.Value         = challenge.MinimumAge;
                comm.Parameters.Add(paramMinimumAge);

                var paramMaximumAge = comm.CreateParameter();
                paramMaximumAge.ParameterName = "@maximum_age";
                paramMaximumAge.Value         = challenge.MaximumAge;
                comm.Parameters.Add(paramMaximumAge);

                var paramName = comm.CreateParameter();
                paramName.ParameterName = "@name";
                paramName.Value         = challenge.Name;
                comm.Parameters.Add(paramName);

                var result = comm.ExecuteNonQuery();
                if (result == 0)
                {
                    log.InfoFormat("Exiting Save with value {0}", challenge);
                    return(challenge);
                }
                else
                {
                    log.InfoFormat("Exiting Save with value {0}", null);
                    return(null);
                }
            }
        }
コード例 #3
0
        public Child FindByProperties(string name, int age)
        {
            log.InfoFormat("Entering FindByProperties with name {0} , age {1}", name, age);
            IDbConnection con = DBUtils.getConnection();

            using (var comm = con.CreateCommand())
            {
                comm.CommandText = "select id , name, age from Child where name = @name and age = @age";

                IDbDataParameter paramName = comm.CreateParameter();
                paramName.ParameterName = "@name";
                paramName.Value         = name;
                comm.Parameters.Add(paramName);

                IDbDataParameter paramAge = comm.CreateParameter();
                paramAge.ParameterName = "@age";
                paramAge.Value         = age;
                comm.Parameters.Add(paramAge);

                using (var dataR = comm.ExecuteReader())
                {
                    if (dataR.Read())
                    {
                        long   id       = dataR.GetInt64(0);
                        String the_name = dataR.GetString(1);
                        int    the_age  = dataR.GetInt32(2);
                        Child  child    = new Child(the_name, the_age);
                        child.Id = id;
                        log.InfoFormat("Exiting FindByProperties with value {0}", child);
                        return(child);
                    }
                }
            }
            log.InfoFormat("Exiting FindByProperties with value {0}", null);
            return(null);
        }