none
save data from xml to Access database RRS feed

  • Question

  • the code of my program looks like this

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

    namespace WindowsApplication1
    {
    public partial class Form1 : Form
    {
    private static bool isValid = true;
    public Form1()
    {
    InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

    private void button1_Click(object sender, EventArgs e)
    {
    OpenFileDialog openFileDialog1 = new OpenFileDialog();
    openFileDialog1.Title = "C# Corner Open File Dialog";
    openFileDialog1.InitialDirectory = @"c:\";
    openFileDialog1.Filter = "All files (*.*)|*.*|All files (*.*)|*.*";
    openFileDialog1.FilterIndex = 2;
    openFileDialog1.RestoreDirectory = true;
    if (openFileDialog1.ShowDialog() == DialogResult.OK)
    {
    textBox1.Text = openFileDialog1.FileName;
    }

    }

    private void button2_Click(object sender, EventArgs e)
    {

    //Create an XmlTextReader object to read an XML document from a text file and then create an XmlValidatingReader to validate this XML data

    XmlTextReader r = new XmlTextReader(openFileDialog1.FileName);
    XmlValidatingReader v = new XmlValidatingReader(r);

    //The ValidationType property of the XmlValidatingReader object indicates the type of validation that is required
    v.ValidationType = ValidationType.Schema;

    v.ValidationEventHandler += new ValidationEventHandler(MyValidationEventHandler);

    while (v.Read())
    {
    // Can add code here to process the content.
    }
    v.Close();

    // Check whether the document is valid or invalid.
    if (isValid)
    textBox2.Text = "Document is valid";
    else

    {
    textBox2.Text = "Document is valid";

    isValid = true;

    }
    }
    public static void MyValidationEventHandler(object sender,
    ValidationEventArgs args)
    {
    isValid = false;
    }

    }
    }
    well.. i have to save the data from that xml in an Acces database(Shiporder) that contains 2 table OrderPerson and Items..

    my XML looks like this

    <shiporder orderid="889923" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="shiporder.xsd">
      <orderperson>John Smith</orderperson>
      <shipto>
        <name>Ola Nordmann</name>
        <address>Langgt 23</address>
        <city>4000 Stavanger</city>
        <country>Norway</country>
      </shipto>
      <item>
        <title>My Title</title>
        <quantity>1</quantity>
        <price>10.12</price>
      </item>
      <item>
        <title>Hide your heart</title>
        <quantity>1</quantity>
        <price>9.90</price>
      </item>
    </shiporder>

    well...no..i hav to save ..orderid..name adress etc in first table

    and title, quantity etc in second table..

    the problem is i dont know how to do this in Access..

    Friday, July 13, 2007 11:54 AM