sql query in XML database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mfkanca
    New Member
    • Jul 2007
    • 2

    sql query in XML database

    Dear All,


    I have to make sql query in XML database with Visual Studio C#.
    I especially need this>>>"SELECT* FROM AAA WHERE BBB='"+ textBox1.Text + "'";


    Thanks for coming helps..
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Originally posted by mfkanca
    Dear All,


    I have to make sql query in XML database with Visual Studio C#.
    I especially need this>>>"SELECT* FROM AAA WHERE BBB='"+ textBox1.Text + "'";


    Thanks for coming helps..
    Hello, mfkanca!

    I came across the below and thought it helpful:



    Be sure to read through it all, pretty fancy stuff. Also, please tell us if the C# portion in your project was questionable, can foward or you can in turn post there. Let us know if above link was helpful or what you got out of it, okay.

    Good luck and welcome!

    Dököll

    Comment

    • mfkanca
      New Member
      • Jul 2007
      • 2

      #3
      Here is the complete answer for myself at the end.There is add,remove,upda te,find commands.


      namespace MOVIE_DATABASE_ with_XML
      {
      public partial class Form1 : Form
      {
      public Form1()
      {
      InitializeCompo nent();
      }

      private XmlNodeList nodes;
      private XmlElement elm0;
      private XmlElement elm1;
      private XmlElement elm2;
      private XmlElement elm3;
      private XmlElement elm4;
      private XmlElement elm5;
      private XmlElement elm6;

      string saveload = "C:\\Docume nts and Settings\\fatih \\Desktop\\Movi eDatabase.xml";
      XmlDocument xmldoc = new XmlDocument();
      private void add_Click(objec t sender, EventArgs e)
      {
      try
      {


      xmldoc.Load(sav eload);

      elm0 = xmldoc.CreateEl ement("Movie");
      elm1 = xmldoc.CreateEl ement("Name");
      elm2 = xmldoc.CreateEl ement("Release_ Date");
      elm3 = xmldoc.CreateEl ement("Genre");
      elm4 = xmldoc.CreateEl ement("Studio") ;
      elm5 = xmldoc.CreateEl ement("Runtime" );
      elm6 = xmldoc.CreateEl ement("Picture" );

      elm1.InnerText = textBox1.Text;
      elm2.InnerText = textBox2.Text;
      elm3.InnerText = textBox3.Text;
      elm4.InnerText = textBox4.Text;
      elm5.InnerText = textBox5.Text;
      elm6.InnerText = textBox6.Text;

      elm0.AppendChil d(elm1);
      elm0.AppendChil d(elm2);
      elm0.AppendChil d(elm3);
      elm0.AppendChil d(elm4);
      elm0.AppendChil d(elm5);
      elm0.AppendChil d(elm6);

      xmldoc.Document Element.InsertA fter(elm0, xmldoc.Document Element.LastChi ld);
      xmldoc.Save(sav eload);
      MessageBox.Show ("It has been just added");

      }
      catch (Exception ex)
      {
      MessageBox.Show ("" + ex.Message);
      }
      }

      private void remove_Click(ob ject sender, EventArgs e)
      {
      try
      {


      xmldoc.Load(sav eload);
      nodes = xmldoc.SelectNo des("/MOVIE_DATABASE//Movie[Name='" + textBox1.Text + "']");

      foreach (XmlNode node in nodes)
      node.RemoveAll( );
      xmldoc.Save(sav eload);
      MessageBox.Show ("It has been just removed");
      }
      catch (Exception ex)
      {
      MessageBox.Show ("" + ex.Message);

      }
      }

      private void update_Click(ob ject sender, EventArgs e)
      {
      try
      {

      xmldoc.Load(sav eload);
      nodes = xmldoc.SelectNo des("/MOVIE_DATABASE//Movie[Name='IceAge']");
      foreach (XmlNode node in nodes)
      {

      node.ChildNodes[1].InnerText = textBox1.Text;
      node.ChildNodes[2].InnerText = textBox2.Text;
      node.ChildNodes[3].InnerText = textBox3.Text;
      node.ChildNodes[4].InnerText = textBox4.Text;
      node.ChildNodes[5].InnerText = textBox5.Text;
      node.ChildNodes[6].InnerText = textBox6.Text;
      }

      xmldoc.Save(sav eload);
      MessageBox.Show ("It has been just updated");
      }
      catch (Exception ex)
      {
      MessageBox.Show ("" + ex.Message);
      }


      }

      private void find_Click(obje ct sender, EventArgs e)
      {
      try
      {

      xmldoc.Load(sav eload);

      nodes = xmldoc.SelectNo des("//MOVIE_DATABASE//Movie[Name='" + textBox1.Text + "']");
      foreach (XmlNode node in nodes)
      {

      textBox1.Text = node.ChildNodes[0].InnerText;
      textBox2.Text = node.ChildNodes[1].InnerText;
      textBox3.Text = node.ChildNodes[2].InnerText;
      textBox4.Text = node.ChildNodes[3].InnerText;
      textBox5.Text = node.ChildNodes[4].InnerText;
      textBox6.Text = node.ChildNodes[5].InnerText;
      }

      }
      catch(Exception ex)
      {
      MessageBox.Show ("" + ex.Message);


      }
      }

      private void button4_Click(o bject sender, EventArgs e)
      {
      openFileDialog1 .InitialDirecto ry = @"C:\Documen ts and Settings\fatih\ Belgelerim\Resi mlerim";
      if (openFileDialog 1.ShowDialog() == DialogResult.OK )
      {
      textBox6.Text = openFileDialog1 .FileName;
      pictureBox1.Ima ge = Image.FromFile( textBox6.Text);
      pictureBox1.Siz eMode = PictureBoxSizeM ode.StretchImag e;



      }
      }

      Comment

      Working...