public void AgregarRole(DTORole role)
        {
            string sSel;
            string sSelCount;
            bool exist;
            sSelCount = "SELECT COUNT(*) FROM \"tbl_Role\" WHERE \"idRole\" = " + role.IdRole + ";";
            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_Role\" VALUES(" + role.IdRole + ",'" + role.Title + "','" + role.Description + "');";

                NpgsqlDataAdapter da;
                DataSet dt = new DataSet();

                try
                {
                    da = new NpgsqlDataAdapter(sSel, sConexion);
                    da.Fill(dt);
                }
                catch (Exception)
                {

                }
            }
        }
示例#2
0
        static void InsertRole(XmlDocument doc)
        {
            try
            {
                Console.WriteLine("Roles");
                DTORole role = new DTORole();
                XmlNodeList roles = doc.ChildNodes[3].ChildNodes[0].ChildNodes[2].ChildNodes[0].ChildNodes;

                foreach (XmlNode r in roles)
                {
                    role.IdRole = Int64.Parse(r.Attributes["id"].Value);
                    role.Title = r.Attributes["title"].Value;
                    role.Description = r.Attributes["desc"].Value;
                    conexion.AgregarRole(role);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }