Exemplo n.º 1
0
        public void AgregarActor(DTOActor actor)
        {
            string sSel;
            string sSelCount;
            bool   exist;

            sSelCount = "SELECT COUNT(*) FROM \"tbl_Actor\" WHERE \"idActor\" = " + actor.IdActor + ";";
            NpgsqlDataAdapter daCount;
            DataSet           dtCount = new DataSet();

            try
            {
                daCount = new NpgsqlDataAdapter(sSelCount, sConexion);
                daCount.Fill(dtCount);
                if (dtCount.Tables[0].Rows[0][0].ToString() == "0")
                {
                    exist = false;
                }
                else
                {
                    exist = true;
                }
            }
            catch (Exception)
            {
                exist = false;
            }
            if (!exist)
            {
                sSel = "INSERT INTO \"tbl_Actor\" VALUES(" + actor.IdActor + ",'" + actor.FirstName + "','" + actor.LastName + "');";

                NpgsqlDataAdapter da;
                DataSet           dt = new DataSet();

                try
                {
                    da = new NpgsqlDataAdapter(sSel, sConexion);
                    da.Fill(dt);
                }
                catch (Exception)
                {
                }
            }
        }
Exemplo n.º 2
0
        static void InsertActor(XmlDocument doc)
        {
            try
            {
                Console.WriteLine("Actores");
                DTOActor    actor  = new DTOActor();
                XmlNodeList actors = doc.ChildNodes[3].ChildNodes[0].ChildNodes[2].ChildNodes[1].ChildNodes;

                foreach (XmlNode n in actors)
                {
                    actor.IdActor   = Int64.Parse(n.Attributes["id"].Value);
                    actor.FirstName = n.Attributes["fname"].Value;
                    actor.LastName  = n.Attributes["lname"].Value;
                    conexion.AgregarActor(actor);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }