Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9057123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:22:24+00:00 2026-06-16T14:22:24+00:00

Hello i need your super help. Im not soo skilled in C# and i

  • 0

Hello i need your super help.
Im not soo skilled in C# and i stack for about 6 hours on this. So please if anyone know help me . Thx

I have Xml like this

<COREBASE>
  <AGENT>
    <AGENT_INDEX>1</AGENT_INDEX>
    <AGENT_PORTER_INDEX>
    </AGENT_PORTER_INDEX>
    <AGENT_NAME>John</AGENT_NAME>
    <AGENT_SURNAME>Smith</AGENT_SURNAME>
    <AGENT_MOBILE_NUMBER>777777777</AGENT_MOBILE_NUMBER>
 </AGENT>
  <AGENT>
    <AGENT_INDEX>2</AGENT_INDEX>
    <AGENT_PORTER_INDEX>1
    </AGENT_PORTER_INDEX>
    <AGENT_NAME>Charles</AGENT_NAME>
    <AGENT_SURNAME>Bukowski</AGENT_SURNAME>
    <AGENT_MOBILE_NUMBER>99999999</AGENT_MOBILE_NUMBER>
 </AGENT>
</COREBASE>

And I need to select agent by index in windows forms combo box and than edit and save his attributes to xml. I found how to edit and save it but i dont know why but its saved to the first agent and overwrite his attributes in XML but not in the selected one.. 🙁

Plese i will be glad for any help

private void buttonEditAgent_Click(object sender, EventArgs e)
{
    XmlDocument AgentBaseEdit = new XmlDocument();
    AgentBaseEdit.Load("AgentBase.xml");

    XDocument AgentBase = XDocument.Load("AgentBase.xml");

    var all = from a in AgentBase.Descendants("AGENT")
              select new
              {
                  agentI = a.Element("AGENT_INDEX").Value,
                  porterI = a.Element("AGENT_PORTER_INDEX").Value,
                  agentN = a.Element("AGENT_NAME").Value,
                  agentS = a.Element("AGENT_SURNAME").Value,
                  agentM = a.Element("AGENT_MOBILE_NUMBER").Value,

              };

    foreach (var a in all)
    {
        if ("" == textBoxEditAgentIndex.Text.ToString())
        {
            MessageBox.Show("You must fill Agent Index field !!", "WARNING");
        }
        else
        {
           // AgentBaseEdit.SelectSingleNode("COREBASE/AGENT/AGENT_INDEX").InnerText == textBoxEditAgentIndex.Text

            if (a.agentI == textBoxEditAgentIndex.Text.ToString())
            {
                AgentBaseEdit.SelectSingleNode("COREBASE/AGENT/AGENT_INDEX").InnerText = textBoxEditAgentIndex.Text;
                AgentBaseEdit.SelectSingleNode("COREBASE/AGENT/AGENT_PORTER_INDEX").InnerText = textBoxEditAgentPorterIndex.Text;
                AgentBaseEdit.SelectSingleNode("COREBASE/AGENT/AGENT_NAME").InnerText = textBoxEditAgentName.Text;
                AgentBaseEdit.SelectSingleNode("COREBASE/AGENT/AGENT_SURNAME").InnerText = textBoxEditAgentSurname.Text;
                AgentBaseEdit.SelectSingleNode("COREBASE/AGENT/AGENT_MOBILE_NUMBER").InnerText = textBoxEditAgentMobile.Text;

                AgentBaseEdit.Save("AgentBase.xml");
                ClearEditAgentTxtBoxes();
            }
        }
    }
}                

Am i on the right way but i dont see the doors or i am totaly wrong ? Thx all. Miko

OK i tried it this way but it didnt changed the inner text

string agentIndex = comboBoxEditAgentI.SelectedItem.ToString();

        XmlDocument AgentBaseEdit = new XmlDocument();
        AgentBaseEdit.Load("AgentBase.xml");

        XDocument AgentBase = XDocument.Load("AgentBase.xml");

        var xElemAgent = AgentBase.Descendants("AGENT")
            .First(a => a.Element("AGENT_INDEX").Value == agentIndex);



        xElemAgent.Element("AGENT_MOBILE_NUMBER").Value = textBoxEditAgentMobile.Text;
        xElemAgent.Element("AGENT_SURNAME").Value = textBoxEditAgentSurname.Text;

        AgentBaseEdit.Save("AgentBase.xml");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T14:22:26+00:00Added an answer on June 16, 2026 at 2:22 pm

    It would be easier if you use Linq2Xml.

    int agentIndex = 2;
    
    XDocument xDoc = XDocument.Load(filename);
    
    var xElemAgent = xDoc.Descendants("AGENT")
                    .First(a => a.Element("AGENT_INDEX").Value == agentIndex.ToString());
    
    //or
    //var xElemAgent = xDoc.XPathSelectElement(String.Format("//AGENT[AGENT_INDEX='{0}']",agentIndex));
    
    xElemAgent.Element("AGENT_MOBILE_NUMBER").Value = "5555555";
    
    xDoc.Save(fileName)
    

    PS: namespaces: System.Xml.XPath System.Xml.Linq

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello i have the this problem, i need your help to figure out what
Hello :) I realy need your help here. I dynamically generate list of items
Hello i am in desperate need of help on this i have an image
Hello guys I'm stucked in a point and I need your help. I want
Hello all and thanks for your time reading this. I need to verify certificates
hello all i really need your help its my final project in university i
hello guys i badly need your help, php noob here, im creating a bulletin
Hello I am only starting to learn php can anyone help. I need to
Hello I hope someone can help me. I need to know how to write
Hello I need your help on the following problem. I am parsing the file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.