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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:48:59+00:00 2026-05-23T12:48:59+00:00

So I know there are many questions on how to update a DB with

  • 0

So I know there are many questions on how to update a DB with linq to SQL, my question is, am I doing this in an accepted standard?

here is my code:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        //load data to page
    }
    else
    {
        using (var db = new App_Data.MyDataContext())
        {
            var Query = (from p in db.peoples
                         where p.ipeople_ID == 59225
                         select p).Single();

            Query.cFirstName = FirstName.Value;

            try { db.SubmitChanges(); }
            catch (ChangeConflictException)
            {
                db.ChangeConflicts.ResolveAll(RefreshMode.KeepChanges);
                db.SubmitChanges();
            }
        }
    }
}

I am learning asp.net by trial and error (and lots of google searches!) so i know it will work, just don’t know if the code would get me laughed out of a conference! 😀

Thanks

  • 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-23T12:49:00+00:00Added an answer on May 23, 2026 at 12:49 pm

    Some changes:

    I would move your logic away from the page load event, and explicitly trigger a save/update event.

    I would address the change conflict if that is happening … I wouldn’t hide that error and attempt to resubmit changes.

    protected void Page_Load(object sender, EventArgs e) {
     if (!IsPostBack){
      //load data to page
     }         
    }
    
    protected void SaveChanges_Click(object sender, EventArgs e) {
     using (var db = new App_Data.MyDataContext()) {
      var person = db.peoples.SingleOrDefault(p=> p.ipeople_ID == 59225);
    
      if(person == null) {
       // notify UI that person doesn't exist
       return;
      }
    
      person.cFirstName = txtFirstName.Text;
    
      try { db.SubmitChanges(); }
      catch (Exception ex){
       //Log error
      }
     }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that there are many different questions about this sort of topic on
I know there are plenty of questions here already about this topic (I've read
friends. I know, there are many questions here already on these iterators. I've read
First things first, there are many questions similar to this, I know, but I
I know there are many questions similar but any of them didn't help. in
NOTE: I know there are many questions that talked about that but I'm still
I know there are already many questions like mine but I found no answer
First of all: I do know that there are already many questions and answers
I know that there are many Delphi database related questions available, but I'm considering
Firstly I know that there are many question and solutions to correct thread marshalling

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.