Como guardar en un xml por medio de una form


Se crea un menu para asignar las diferentes funciones del proceso a mostrar


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Trabajo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void guardarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form2 Formulario = new Form2();
            Formulario.MdiParent = this;
            Formulario.Show();
        }

        private void archivoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form3 Formulario = new Form3();
            Formulario.MdiParent = this;
            Formulario.Show();
        }

        private void salirToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Trabajo
{
    public partial class Form2 : Form
    {
        DataSet dsDatos = new DataSet("Datos");
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            //se carga al abrir el form
            dsDatos.ReadXml("Datos.xml");
            txtClave.DataBindings.Add("Text", dsDatos, "Producto.Clave");
            txtDescripcion.DataBindings.Add("Text", dsDatos, "Producto.Descripcion");
            txtventas.DataBindings.Add("Text", dsDatos, "Producto.ventas");
        }

        private void button1_Click(object sender, EventArgs e)
        {
           //agregar
            this.BindingContext[dsDatos, "Producto"].EndCurrentEdit();
            this.BindingContext[dsDatos, "Producto"].AddNew();
           dsDatos.WriteXml("Datos.xml");
        }
    }
}





using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace Trabajo
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }

        private void buttonCargar_Click(object sender, EventArgs e)
        {
           DataSet  dsDatos = (DataSet)dataGridView1.DataSource;
           dsDatos.WriteXml("Datos.xml");

        }

        private void Form3_Load(object sender, EventArgs e)
        {
            XmlDataDocument dsDatos = new XmlDataDocument();
            dsDatos.DataSet.ReadXml(Application.StartupPath + "\\Datos.xml");

            dataGridView1.DataSource = dsDatos.DataSet;
            dataGridView1.DataMember = "Producto";
        }
    }
}
se crea un xml con el que se va a trabajar llamado Datos ahi se almacena la informacion en diferentes etiquetas

Programa hecho en visual studio
lenguaje: c#
Descripcion: es una presentacion para mostrar el guardar de una forma a otra por medio de un xml


Comentarios

Entradas populares de este blog

Google Glass llegará al mercado en 2014

Suma y Multiplicacion de Matrices php

Como sobrevivir a mi ex