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 8651467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:04:49+00:00 2026-06-12T14:04:49+00:00

I am a .net beginner. I am trying to update my xml file using

  • 0

I am a .net beginner.

I am trying to update my xml file using linq.

I got stuck at the very first point of it i.e i cant grab the value from xml file using linq.

These are the controls I am using in my code:

cbBrandName -- combobox
cbProduct   -- combobox
txtQuantity -- TextBox

I am trying the below code:

XElement doc = XElement.Load(@"..\..\stock.xml");
string quantity = doc.Descendants("quantity")
                  .Select(y => y.Element("quantity").Value.Equals(txtQuantity.Text))
/*red scribbles to 'Element' in 'where'*/ 
                  .Where(x => x.Element("productname").Value.Equals(cbProduct.Text) &&
                  x.Element("brandname").Value.Equals(cbBrandName.Text)).ToString();
MessageBox.Show(quantity.ToString());

here I am trying to store the “quantity” value in quantity string so that i can manipulate it later and then again update to my xml file.

when I make .select as comment it isn’t showing any errors but when i run it, instead of text it is showing some system.linq.Enumerable + ..... in the MessageBox.

EDIT:

enter image description here

when i give .toString() at the end it. It is showing error — “Object reference not set to an instance of an object.” when i run it.

Please help

Thanks in Advance.

  • 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-12T14:04:50+00:00Added an answer on June 12, 2026 at 2:04 pm
    XElement doc = XElement.Load(AppDomain.CurrentDomain.BaseDirectory + "/App_Data/XMLFile.xml");
            string quantity = doc.Descendants("items")
            .Select(y => y.Element("quantity").Value)
            .Where(x => x.Element("productname").Value.Equals(cbProduct.text) && x.Element("brandname").Value.Equals(cbBrandName.text))
            .Single().Element("quantity").Value;
    

    THIS WORKS

    UPDATING XML VALUE

     doc.Descendants("items")
        .Where(x => x.Element("productname").Value.Equals(cbProduct.Text) && x.Element("brandname").Value.Equals(cbBrandName.Text))
        .Single().Element("quantity").SetValue(quantity);
            doc.Save(AppDomain.CurrentDomain.BaseDirectory + "/App_Data/XMLFile.xml");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a beginner in LINQ. I am using .NET 3.5. and VS 2008.
I am a beginner in using Asp.NET with C# and it is my first
What I got: http://jsfiddle.net/nCs88/ What I'm trying to get: http://img545.imageshack.us/img545/888/42576e33afe343a0bab6a40.png I'm an absolute beginner,
im pretty much a beginner to using ASP.net and linq to sql but what
I am a total total beginner in Java actually I am .net dev trying
I am a beginner in ASP.Net. I am starting a new project using ASP.Net
Probably a very basic beginner question. Imagine the following situation: I have an ASP.NET
I am a beginner coder, i am building a project using C# Asp.Net in
Can someone point me to good resource for Net::HTTP? I'm trying to understand why
trying to migrate my existing asp.net website which is using mysql to Windows Azure

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.