using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Xml;
namespace Sistema2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private const string m_strFileName = "sistemas.xml";
private System.Data.OleDb.OleDbConnection cnn;
private OleDbCommand aCommand;
private OleDbDataReader aReader;
private void Form1_Load(object sender, EventArgs e)
{
XmlTextWriter bankWriter = null;
bankWriter = new XmlTextWriter(m_strFileName, null);
try
{
bankWriter.Formatting = Formatting.Indented;
bankWriter.Indentation = 6;
bankWriter.Namespaces = false;
bankWriter.WriteStartDocument();
}
catch (Exception e5)
{
MessageBox.Show(e5.ToString());
}
cnn = new System.Data.OleDb.OleDbConnection();
cnn.ConnectionString = @"PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=sistemas.mdb";
cnn.Open();
aCommand = new OleDbCommand("select * from T_Sistema", cnn);
try
{
bankWriter.WriteStartElement("", "sistema", "");
//create the datareader object to connect to table
aReader = aCommand.ExecuteReader();
//Iterate throuth the database
while (aReader.Read())
{
bankWriter.WriteStartElement("", "id", "");
bankWriter.WriteString(aReader.GetInt32(0).ToString());
bankWriter.WriteEndElement();
bankWriter.WriteStartElement("", "descripcion", "");
bankWriter.WriteString(aReader.GetString(1));
bankWriter.WriteEndElement();
cmbListar.Items.Add(aReader.GetString(1));
}
//close the reader
aReader.Close();
//close the connection Its important.
cnn.Close();
}
//Some usual exception handling
catch (OleDbException ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
if (bankWriter != null)
{
bankWriter.WriteEndElement();
bankWriter.Flush();
bankWriter.Close();
}
}
}
private void cmbListar_SelectedIndexChanged(object sender, EventArgs e)
{
int itemSel = cmbListar.SelectedIndex;
//txtDesc.Text = itemSel.ToString();
XmlTextReader bankReader = null;
bankReader = new XmlTextReader (m_strFileName);
txtDesc.Text = "<sistema>";
while (bankReader.Read())
{
if (bankReader.NodeType == XmlNodeType.Element)
{
if (bankReader.LocalName.Equals("id"))
{
//txtDesc.Text = bankReader.ReadString();
}
}
}
txtDesc.Text += "</sistema>";
}
}
}