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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:49:48+00:00 2026-05-26T17:49:48+00:00

So basically I have this field in XML that I want to update. It

  • 0

So basically I have this field in XML that I want to update. It is parsed out through XML and I am not sure how to update this single record from this single instance.

var dataContext = 
    new RequestFormsDBDataContext(ConfigManager.Data.ConnectionString);

var userForm = (
    from i in dataContext.RequestFormItems
    join c in dataContext.RequestFormInstances on i.TypeGuid equals c.TypeGuid
    where i.Id == FormID
    select new {
        i.Id,
        XmlData = XElement.Parse(i.XML)
    }
).ToList();


// Parsing out XML Data
var userFormParced = (
    from i in userForm
    select new FormItem {
        FormId = i.Id,
        DateTimeCompleted = i.XmlData.Element("DateTimeCompleted").Value
    }
).FirstOrDefault();

RFDateTimeCompleted = userFormParced.DateTimeCompleted;

// Code that isnt working
userFormParced.DateTimeCompleted = "New Data";
dataContext.SubmitChanges();
  • 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-05-26T17:49:49+00:00Added an answer on May 26, 2026 at 5:49 pm

    This won’t work because you aren’t changing the instance that you retrieve from the database. You are creating a new object using the values from the original – twice – and then changing it. The LINQ-to-SQL context has no knowledge that you’re changing database rows, just some unrelated XML that you’ve constructed.

    Firstly, the value you retrieve from the database is being put into an XElement

    XmlData = XElement.Parse(i.XML)
    

    and then you retrieve the ‘value’ from a node and put it into another new object

    select new FormItem 
    {         
        FormId = i.Id,         
        DateTimeCompleted = i.XmlData.Element("DateTimeCompleted").Value     
    } 
    

    It’s lost any reference to the LINQ-to-SQL context by this stage. Instead you need to change it in place.

    If you’re using XML in your database, you should be using XML columns which map to XML properties in your LINQ-to-SQL objects. You’re not, so we’ll implement a workaround.

    Try something like this.

    // just get the item
    var userForm = (
        from i in dataContext.RequestFormItems
        join c in dataContext.RequestFormInstances on i.TypeGuid equals c.TypeGuid
        where i.Id == FormID
        select i).FirstOrDefault();
    
    // parse the XML
    var xml = XElement.Parse(userForm.XML);
    
    RFDateTimeCompleted = xml.Element("DateTimeCompleted").Value;
    xml.Element("DateTimeCompleted").Value = "New Data";
    
    // and finally, because you're again just changing XML 
    // unrelated to the context, update the original object
    userForm.XML = xml.ToString();
    context.SubmitChanges();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this error that is keeping me from moving forward. I basically have
Well basically I have this script that takes a long time to execute and
I have this form. Basically what I want is to send a auto-response with
Basically, I have this webpage that is the header on any page you go
Basically, I want to do the reverse of this question . I'm getting XML
I have a property field in a class that is of type javax.xml.datatype.Duration .
ok, so, i have an xml file that looks like this: <?xml version=1.0?> <Users>
not sure if this is possible without having to go through several passes, but
Say i have this sample XML. <result> <field k='field1'> <value h='1'><text>text_value1</text></value> </field> <field k='field2'>
I basically have something like this: void Foo(Type ty) { var result = serializer.Deserialize<ty>(inputContent);

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.