public void AgregarValorPrograma(DTOProgramValue value) { string sSel; string sSelCount; bool exist; sSelCount = "SELECT COUNT(*) FROM \"tbl_ProgramValue\" WHERE \"idProgramValue\" = " + value.IdProgramValue; 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_ProgramValue\" VALUES(" + value.IdProgramValue + ",'" + value.Name + "','" + value.Pname + "','" + value.Description + "')"; NpgsqlDataAdapter da; DataSet dt = new DataSet(); try { da = new NpgsqlDataAdapter(sSel, sConexion); da.Fill(dt); } catch (Exception) { } } }
static void InsertProgramValues(XmlDocument doc) { try { Console.WriteLine("Valor de Programas"); DTOProgramValue valor = new DTOProgramValue(); XmlNodeList programValues = doc.GetElementsByTagName("glf")[0].ChildNodes[0].ChildNodes[6].ChildNodes; foreach (XmlNode value in programValues) { valor.IdProgramValue = Int64.Parse(value.Attributes["id"].Value); valor.Name = value.Attributes["name"].Value; valor.Pname = value.Attributes["pname"].Value; valor.Description = value.Attributes["desc"].Value; conexion.AgregarValorPrograma(valor); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }