예제 #1
0
        public Boolean update(Childe childe)
        {
            Boolean result = false;

            MySqlConnection  connection   = null;
            MySqlCommand     mysqlCmd     = null;
            MySqlDataAdapter mysqlAdapter = null;
            int codigop;

            codigop = this.poblacionCod(childe.Poblacion);
            String sql;

            sql = "UPDATE nino SET carnet='" + childe.Carnet + "',nombre='" + childe.Name + "',apellidos='" + childe.Apellidos + "', direccion='" + childe.Direccion + "', sexo='" + childe.Sexo + "', anio_nac='" + childe.Anionac + "', codigo_poblacion=" + codigop
                  + " WHERE carnet =" + childe.Carnet;

            try
            {
                connection = dataSource.getConnection();
                connection.Open();
                mysqlCmd     = new MySqlCommand(sql, connection);
                mysqlAdapter = new MySqlDataAdapter(mysqlCmd);
                mysqlCmd.ExecuteNonQuery();
                result = true;
            }
            catch (Exception e)
            {
                Console.Write(e);
                result = false;
            }
            finally
            {
                if (mysqlCmd != null)
                {
                    mysqlCmd.Dispose();
                }
                if (mysqlAdapter != null)
                {
                    mysqlAdapter.Dispose();
                }
                if (connection != null)
                {
                    connection.Close();
                }
            }

            return(result);
        }
예제 #2
0
        //Añadir el niño
        public Boolean add(Childe childe)
        {
            Boolean          result       = true;
            DataSet          dataNino     = new DataSet();
            MySqlConnection  connection   = null;
            MySqlCommand     mysqlCmd     = null;
            MySqlDataAdapter mysqlAdapter = null;
            int codigop;

            codigop = this.poblacionCod(childe.Poblacion);

            String sql;

            sql = "INSERT INTO `nino`(`carnet`, `nombre`, `apellidos`, `direccion`, `sexo`, `anio_nac`, `codigo_poblacion`) VALUES (" + childe.Carnet + ", '" + childe.Name + "', '" + childe.Apellidos + "', '" + childe.Direccion + "', '" + childe.Sexo + "', '" + childe.Anionac + "', " + codigop + ")";
            try
            {
                connection = dataSource.getConnection();
                connection.Open();
                mysqlCmd     = new MySqlCommand(sql, connection);
                mysqlAdapter = new MySqlDataAdapter(mysqlCmd);
                mysqlCmd.ExecuteNonQuery();
                result = true;
            }
            catch (Exception e)
            {
                Console.Write(e);
                result = false;
            }
            finally
            {
                if (mysqlCmd != null)
                {
                    mysqlCmd.Dispose();
                }
                if (mysqlAdapter != null)
                {
                    mysqlAdapter.Dispose();
                }
                if (connection != null)
                {
                    connection.Close();
                }
            }

            return(result);
        }