Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. xml file embedded: can´t save changes

xml file embedded: can´t save changes

Scheduled Pinned Locked Moved C#
comhardwarexmlhelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nelsonpaixao
    wrote on last edited by
    #1

    Hi, i have a xml file embedded in my project resources. I can read it but i can´t save changes on it, check code bellow

    // class_helper.ResourcesXml_Login is the xml file!

    DataSet ds = new DataSet();
    ds.ReadXml(Class_Helper.ResourceXml_login, XmlReadMode.ReadSchema);
    DataGridView_Administrator.DataSource = ds.Tables[0];
    DataRow DataRow_user = ds.Tables[0].NewRow();
    DataRow_user["id"] = 10;
    DataRow_user["f_name"] = ToolStripTextBox_FName.Text;
    DataRow_user["l_name"] = ToolStripTextBox_LName.Text;
    DataRow_user["username"] = ToolStripTextBox_Username.Text;
    DataRow_user["password"] = ToolStripTextBox_Password.Text;
    DataRow_user["role"] = ToolStripComboBox_Role.Text;
    ds.Tables[0].Rows.Add(DataRow_user);
    ds.WriteXml(Class_Helper.ResourceXml_login,XmlWriteMode.WriteSchema);
    DataGridView_Administrator.DataSource = ds.Tables[0];

    i can save changes if i use the path way you know?! but i want this way and i really dont know where the codes goes wrong :doh:

    nelsonpaixao@yahoo.com.br trying to help & get help

    D 1 Reply Last reply
    0
    • N nelsonpaixao

      Hi, i have a xml file embedded in my project resources. I can read it but i can´t save changes on it, check code bellow

      // class_helper.ResourcesXml_Login is the xml file!

      DataSet ds = new DataSet();
      ds.ReadXml(Class_Helper.ResourceXml_login, XmlReadMode.ReadSchema);
      DataGridView_Administrator.DataSource = ds.Tables[0];
      DataRow DataRow_user = ds.Tables[0].NewRow();
      DataRow_user["id"] = 10;
      DataRow_user["f_name"] = ToolStripTextBox_FName.Text;
      DataRow_user["l_name"] = ToolStripTextBox_LName.Text;
      DataRow_user["username"] = ToolStripTextBox_Username.Text;
      DataRow_user["password"] = ToolStripTextBox_Password.Text;
      DataRow_user["role"] = ToolStripComboBox_Role.Text;
      ds.Tables[0].Rows.Add(DataRow_user);
      ds.WriteXml(Class_Helper.ResourceXml_login,XmlWriteMode.WriteSchema);
      DataGridView_Administrator.DataSource = ds.Tables[0];

      i can save changes if i use the path way you know?! but i want this way and i really dont know where the codes goes wrong :doh:

      nelsonpaixao@yahoo.com.br trying to help & get help

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Of course you can't do this. First of all, resources are Read Only. Second, in order to save those changes, the .EXE file cannot be running because a running .EXE's file is locked by the system. So, in order to update the resource, you have to NOT be running the code.

      nelsonpaixao wrote:

      but i want this way and i really dont know where the codes goes wrong

      It's not the code that's going wrong, but your entire concept. You simply cannot do what you want.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008

      N 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Of course you can't do this. First of all, resources are Read Only. Second, in order to save those changes, the .EXE file cannot be running because a running .EXE's file is locked by the system. So, in order to update the resource, you have to NOT be running the code.

        nelsonpaixao wrote:

        but i want this way and i really dont know where the codes goes wrong

        It's not the code that's going wrong, but your entire concept. You simply cannot do what you want.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008

        N Offline
        N Offline
        nelsonpaixao
        wrote on last edited by
        #3

        thanks, i didn´t know that. :) i will use the path method.

        nelsonpaixao@yahoo.com.br trying to help & get help

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups