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

  • Home
  • SEARCH
  • 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 6767655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:58:39+00:00 2026-05-26T14:58:39+00:00

I am reading a book – ASP.Net 3.5 Enterprise Application Development with Visual Studio

  • 0

I am reading a book – ASP.Net 3.5 Enterprise Application Development with Visual Studio 2008 and when it talks about updating a record in the database using Linq-to-SQL it uses this code:

MyUserAccount ua = new MyUserAccount
{
... Update fields
};

ua.UserAccountID = Convert.ToInt32(session["UserAccountID"]);
ua.Version = Convert.ToInt32(session["Version"]);

MyDataContext db = new MyDataContext();
db.MyUserAccounts.Attach(ua,true);
db.SubmitChanges();

Versus what I am used to, where I just save the AccountID in a session variable
and then get the record from the database, make my changes, and then submit the changes.

BtnUpdate

int UserAccountID = Convert.ToInt32(Request["UserAccountID"]);

//Get User fron Context
MyDataContext db = new MyDataContext();
MyUserAccount ua = db.MyUserAccounts.Single(
     x => x.UserAccountID == UserAccountID);

//Make changes
ua.Blah = "";

db.SubmitChanges();

So my question is what is the preferred way to do this? Having not seen this in the past I am not sure what the preferred or best way is. Any help is appreciated.

Wade

Note:

My original question, someone changed my title, was what was the best Linq-to-SQL way to update the record. So I changed the code to use session variables and the title back to it’s original. Please, read the whole question as I am only looking for the best method to update my record in the database using Linq-to-SQL.

  • 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-26T14:58:40+00:00Added an answer on May 26, 2026 at 2:58 pm

    In terms of sql produced the former will generate a Sql statement something like

    Update MyUserAccount set blah=@Blah where UserAccountID = @UserAccountID
    

    whereas the latter will produce

    Select UserAccountID, Blah, ....  From MyUserAccount where UserAccountID = @UserAccountID
    Update MyUserAccount set blah=@Blah where UserAccountID = @UserAccountID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While reading a book about JavaScript I stumbled across an example: var names =
I've been reading the book Enterprise Rails by Dan Chak and it got me
I'm reading this book on C# and .NET and I'm learning a bunch of
I've been reading a book which is in C#. I'm a VB.NET developer (and
I was reading a book about AJAX and the writer said that one should
I'm reading a book about data structures in java, and it's talking about iterators
I'm currently reading a book on .Net 4.0 with C# and I read a
Reading a book (VS 2010), it says that commands (statements) in .NET Csharp cannot
I am reading a book about Java and it says that you can declare
Recently i'm reading the book Operating System Concepts Chapter VI about critical section problem,

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.