Can't Insert new record from WPF Datagrid via LINQ-to-SQL -


OK, what I'm doing (I think) is rather simple

I have a LINQ-to-SQL data reference set and one of the users in the designer, in the designer, it shows the source as "dbo.Users" as "user". This access is public, and I can just access the database to get it properly and update.

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

  1. I have AutoGenerateColumns set to set datagrid = "true"
  2. CanUserAddRows "correct"
  3. The RowEditEnding event is set to a method .

When I add a record (SubmitChanges ()) in the context of data, nothing happens. It just does not include I have checked local objects in breakpoint and all the signs are that it is actually there and it has a correct record that it should be added.

But wait, there's even more.

If I execute Users.InsertOnSubmit () and pass the currentItem of datagrid (user casted), it is telling me, but I think the record is actually inserted "is a unit That can not already exist "gives an error.

Does anyone have a clue?

(Fwiw, backend is SQL2K8 express)

Edit: The code that gives no exception, but does not add the record
Either:

< Pre> Private Zero UserGrid_RoedIndInding (Object Sender, DataGridRoEdit Anting Agreement E) {ctx.SubmitChanges (); }

and the code that gives an exception:

  Private zero UserGrid_RowEditEnding (Object Sender, DataGridRowEditEndingEventArgs e) {ctx.Users.InsertOnSubmit (user E.Row.Item); Ctx.SubmitChanges (); }  

The problem is that you are using the same data reference as if you were using Datagrid . Do not do this Create a new data reference for every small task they are cheap, which is cheaper than conversion tracking, which are collected using the same reference for an extended period.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -