Guardar valores | Cargar valores |
· Abres el archivo · Guardas todos los valores (uno por linea) · Cierras el archivo | · Abres el archivo · Lees los valores una línea a la vez y los asignas a la variable correspondiente · Cierras el archivo |
Cita de: El Benjo en 15 Enero 2014, 23:44 PM
también puedes utilizar My.Settings para guardar variables dentro de tu aplicación y cuyos valores estarán ahí la próxima vez que la aplicación se ejecute.
<?xml version="1.0" encoding="Windows-1252"?>
<!--Mi base de datos-->
<Verduras>
<Verdura><Nombre>Cebolla</Nombre><Precio>15</Precio></Verdura>
<Verdura><Nombre>Chile</Nombre><Precio>25</Precio></Verdura>
<Verdura><Nombre>Limón</Nombre><Precio>25</Precio></Verdura>
<Verdura><Nombre>Papa</Nombre><Precio>18</Precio></Verdura>
<Verdura><Nombre>Plátano</Nombre><Precio>10</Precio></Verdura>
<Verdura><Nombre>Tomate</Nombre><Precio>27</Precio></Verdura>
</Verduras>
Dim Verduras = From Verdura As XElement
In XDoc.<Verduras>.<Verdura>
Select New With
{
Verdura.<Nombre>.Value,
Verdura.<Precio>.Value
}
For Each Verdura In Verduras
MsgBox(String.Format("Nombre: {0}; Precio: {1}",
Fruta.Nombre,
Fruta.Precio))
Next Verdura
Citarprivate void button7_Click(object sender, EventArgs e)
{
XmlWriter w = XmlWriter.Create(@"C:\xmle\verduras.xml");
w.WriteStartElement("Verduras");
w.WriteElementString("Tomate", textBox1.Text.ToString());
w.WriteElementString("Limon", textBox2.Text.ToString());
w.WriteElementString("Papa", textBox3.Text.ToString());
w.WriteElementString("Cebolla", textBox4.Text.ToString());
w.WriteElementString("Platano", textBox5.Text.ToString());
w.WriteEndElement();
w.Close();
MessageBox.Show("Se han guardado correctamente los precio");
}
Citar
XmlReader r = XmlReader.Create(@"C:\xmle\verduras.xml");
r.ReadStartElement("Verduras");
textBox1.Text = r.ReadElementContentAsString();
textBox2.Text = r.ReadElementContentAsString();
textBox3.Text = r.ReadElementContentAsString();
textBox4.Text = r.ReadElementContentAsString();
textBox5.Text = r.ReadElementContentAsString();
r.Close();