none
Temporary identity RRS feed

  • Question

  • I' ve got a weird situation to solve.
    I've got two forms and one bindingsource linked to a table from a SQLCE database .
    The first form simply shows data in a datagridview, the second one, a modal form, edits/inserts one record at a time in a details view.
    When I add a row in the second form and come back to the datagridview, I still see the new row with the temporary identity of -1, -2 and so on.
    Even if I updated data to database after adding.
    What I want is to see the real identity, given by the database. The only way to have this is to close and reopen the app.
    Why do I want this? Because editing a row with -1 primary identity raise an exception and I cannot edit without having all the row correctly updated.
    Could you help me?
    ------- Life is what happens while doing other projects -------
    Sunday, July 12, 2009 2:54 PM

Answers

  • I finally found the problem.
    It was connected to a datetimepicker bound to a datetime field .

    If I remove this code, everything starts working again. It works like the small project I created ad hoc early.

    MyDateTimePicker.DataBindings.Add("Value", this.MyBindingSource, "DateTimePropertyName");

    Maybe because the datetime null interferes with select or update queries.

    For anyone getting the exception "", have a look at all controls, specifically those bound to not nullable types. This is my tip.


    ------- Life is what happens while doing other projects -------
    • Marked as answer by Italian Cousin Wednesday, July 15, 2009 11:22 AM
    Wednesday, July 15, 2009 11:22 AM

All replies

  • Hey Italian Cousin,

    I'm not sure I have much to advise to offer. I think at this point we need to gain more information by debugging the situation. When you call Update does it return back an integer that relates to how many changes should have been made. What are the fill options on the adapter? The only think I can think of is that when you call Fill its not clearing the previous results in there.

    Can you verify that you have each control binded to the DataTable?

    Thanks
    Chris Robinson
    Program Manager - DataSet
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Tuesday, July 14, 2009 12:53 AM
  • Hi Chris,
    this is my feedback, when I edit an existing record the Update return 1. The same when I add a new row.
    But, if I dare to edit a row with -1 identity, created in the past but not reloaded from database beneath, I receive this exception (traslated from my language):
    "Concurrency violation: UpdateCommand modified 0 of 1 in provided rows. "

    What do you mean for fill options ?
    Each control seems to be correctly bound. But I will check better.

    See you.
    ------- Life is what happens while doing other projects -------
    Tuesday, July 14, 2009 11:46 AM
  • Perhaps there is an better answer on this existing thread.
    http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/bfdb40a8-0e29-4897-8251-6368abe24516

    It appears to me that the update is not working, I'm guessing that the relationships or fks aren't hooked up right. Perhaps the updates are not happening in the correct order.

    Thanks
    Chris Robinson
    Program Manager - DataSet
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Tuesday, July 14, 2009 6:05 PM
  • Thanks, there I found a lot of ideas but no one solving.
    Next step, I prepared a very small VB2008 solution that you can find here (link removed)

    Step to reproduce the problem:
    1. Build and execute
    2. Delete any record with the delete button
    3. Once you have an empty recordset, insert the first row with add button (ID becomes -1)
    4. Fill in name and surname fields as you like
    5. Add another row with add button (ID becomes -2)
    6. Fill in name and surname fields as you like
    7. Push save (save data button)
    8. Move to first row with left arrow (Move to previous button): now you are in -1 row
    9. Change the name
    10. Push save (save data button)    <------------- HERE YOU GET THE EXCEPTION
    If you solve this, I will be on the right path. Post here the changes.
    Thanx.

    ------- Life is what happens while doing other projects -------
    Tuesday, July 14, 2009 7:24 PM
  • One step ahead. If I change this

    private void table1BindingNavigatorSaveItem_Click(object sender, EventArgs e)
            {
                this.Validate();
                this.table1BindingSource.EndEdit();
                this.tableAdapterManager.UpdateAll(this.databaseDS);
            }

    into this:

    private void table1BindingNavigatorSaveItem_Click(object sender, EventArgs e)
            {
                this.Validate();
                this.table1BindingSource.EndEdit();
                this.tableAdapterManager.UpdateAll(this.databaseDS);
                this.table1TableAdapter.Fill(this.databaseDS.Table1);
    
            }
    then issue is solved. Now I need to understand where I'm wrong.
    ------- Life is what happens while doing other projects -------
    Tuesday, July 14, 2009 7:41 PM
  • This makes complete sense. Because after you commit the changes need to filled back in.

    Thanks
    Chris
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Tuesday, July 14, 2009 7:59 PM
  • OK, now I completely reproduced my solution with a smaller copy.
    The main difference is that the table schema is much simpler, only 1 integer identity autoincrement and two varchar.

    AND IT WORKS!

    So the problem is in the TableAdapter internal command execution: select, update and so on.

    This is my original schema:

    row.ID (primary key)
    row.Nome (varchar)
    row.Indirizzo (varchar)
    row.Settore (varchar)
    row.Età (smallint)
    row.Telefono1 (varchar)
    row.Telefono2 (varchar)
    row.Nazionalità (varchar)
    row.PrezzoMin (money)
    row.Foto1 (image)
    row.Foto2 (image)
    row.Foto3 (image)
    row.GiudEstetico (varchar)
    row.GiudPratico (varchar)
    row.Valutata (bit)
    row.Note (varchar)
    row.VotoSintetico (smallint)
    row.Città (varchar)
    row.UltimaModifica (datetime)

    All nullable a part from ID field. What can I do? I'm stuck!
    ------- Life is what happens while doing other projects -------
    Tuesday, July 14, 2009 8:27 PM
  • I finally found the problem.
    It was connected to a datetimepicker bound to a datetime field .

    If I remove this code, everything starts working again. It works like the small project I created ad hoc early.

    MyDateTimePicker.DataBindings.Add("Value", this.MyBindingSource, "DateTimePropertyName");

    Maybe because the datetime null interferes with select or update queries.

    For anyone getting the exception "", have a look at all controls, specifically those bound to not nullable types. This is my tip.


    ------- Life is what happens while doing other projects -------
    • Marked as answer by Italian Cousin Wednesday, July 15, 2009 11:22 AM
    Wednesday, July 15, 2009 11:22 AM