title: Update XML element with LINQ to XML in VB.NET
body: <p>I'm trying to update an element in the XML document below:</p>
  
  <p>Here's the code:</p>
  
  <pre><code>Dim xmldoc As XDocument = XDocument.Load(theXMLSource1)
          Dim ql As XElement = (From ls In xmldoc.Elements("LabService") _
                  Where CType(ls.Element("ServiceType"), String).Equals("Scan") _
                  Select ls.Element("Price")).FirstOrDefault
  
  
          ql.SetValue("23")
          xmldoc.Save(theXMLSource1)
  </code></pre>
  
  <p>Here's the XML file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!--Test XML with LINQ to XML--&gt;
  
  &lt;LabSerivceInfo&gt;
  
    &lt;LabService&gt;
      &lt;ServiceType&gt;Copy&lt;/ServiceType&gt;
      &lt;Price&gt;1&lt;/Price&gt;
    &lt;/LabService&gt;
  
    &lt;LabService&gt;
      &lt;ServiceType&gt;PrintBlackAndWhite&lt;/ServiceType&gt;
      &lt;Price&gt;2&lt;/Price&gt;
    &lt;/LabService&gt;
  
  &lt;/LabSerivceInfo&gt;
  </code></pre>
  
  <p>But, I got this error message:</p>
  
  <pre><code>Object reference not set to an instance of an object.
  Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
  
  Error line:ql.SetValue("23")
  </code></pre>
  
  <p>Can you show me what the problem is? Thank you.</p>