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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:47:40+00:00 2026-05-22T01:47:40+00:00

Ok, what I’m doing is (I think) rather simple. I have a LINQ-to-SQL data

  • 0

Ok, what I’m doing is (I think) rather simple.

I have a LINQ-to-SQL data context set up and one of the tables is Users. In the designer, it shows the class as “User” with the source as “dbo.Users”. It’s access is Public, and I can reach the database to retrieve and update just fine. The class is set to “Use Runtime” for the I/D/U operations.

The problem comes when I try to add a new record.

  1. I have the datagrid set to AutoGenerateColumns =”True”
  2. CanUserAddRows is set to “True”
  3. RowEditEnding event is set to a method.

When I add a record (SubmitChanges() on the data context), nothing happens. It simply does not do the insert. I’ve checked the local objects at a breakpoint and all indications are that it’s indeed there and it does have the correct record that it should be adding.

But wait, there’s more.

If I execute Users.InsertOnSubmit() and pass the datagrid’s CurrentItem (casted to user), it gives me an error saying “cannot add an entity that already exists” BUT I find that the record has actually been inserted.

Does anyone have a clue?

(FWIW, the backend is SQL2K8 Express)

EDIT:
The code that gives no exception but doesn’t add the record either:

         private void UserGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e) 
     { 
         ctx.SubmitChanges(); 
     } 

and the code that gives an exception:

        private void UserGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e) 
    { 
        ctx.Users.InsertOnSubmit((User) e.Row.Item); 
        ctx.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-22T01:47:41+00:00Added an answer on May 22, 2026 at 1:47 am

    The problem is that you are using the same data context as you’re datagrid. Don’t do that. Create a new data context for each small task. They are cheap, much cheaper than the change tracking that accumulates when using the same context for an extended period.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.