Update-Insert DetailsView, result is duplicating lines

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Barno77
    New Member
    • Oct 2007
    • 22

    Update-Insert DetailsView, result is duplicating lines

    Everytime I edit a record, and hit update I get duplicating lines in my Details View. Here's my If statement:

    Code:
    If (Len(e.OldValues("AutoNumber")) > 0) Then
                sql = "UPDATE SHIP_LOG SET FileNumber='" & e.NewValues("FileNumber") & "',BOL='" & e.NewValues("BOL") & "',Container='" & e.NewValues("Container") & "',DESTN='" & e.NewValues("DESTN") & "', Comments='" & e.NewValues("Comments") & "' WHERE POD_COMINV='" & e.Keys("POD_COMINV") & "' AND LineIndex='" & e.Keys("LineIndex") & "'"
            Else
                sql = "INSERT INTO SHIP_LOG (POD_COMINV,FileNumber,BOL,Container,DESTN,Comments,LineIndex) VALUES ('" & e.Keys("POD_COMINV") & "','" & e.NewValues("FileNumber") & "','" & e.NewValues("BOL") & "','" & e.NewValues("Container") & "','" & e.NewValues("DESTN") & "','" & e.NewValues("Comments") & "','" & e.Keys("LineIndex") & "')"
            End If
    Any ideas???

    Thanks
    Last edited by Curtis Rutland; Sep 23 '08, 03:27 PM. Reason: Added Code Tags - Please surround your code with [CODE] and [/CODE]
  • mldisibio
    Recognized Expert New Member
    • Sep 2008
    • 191

    #2
    Is this code for a System.Data.Dat aTable update? Please clarify.

    Is the data bound to a DataGrid?
    What event are you using to trigger this update/insert?

    Sounds like you are manually processing updates done manually in a DataGridView.
    Do you have an additional DataAdapter.Upd ate() statement that might be automatically updating the modified rows on its own?

    Comment

    • Barno77
      New Member
      • Oct 2007
      • 22

      #3
      Originally posted by mldisibio
      Is this code for a System.Data.Dat aTable update? Please clarify.

      Is the data bound to a DataGrid?
      What event are you using to trigger this update/insert?

      Sounds like you are manually processing updates done manually in a DataGridView.
      Do you have an additional DataAdapter.Upd ate() statement that might be automatically updating the modified rows on its own?

      Yes, the data is bound to a Gridview when I enter INV #.
      Event I'm using is DetailsView1_It emUpdating. No additional Update statement!

      Comment

      • Curtis Rutland
        Recognized Expert Specialist
        • Apr 2008
        • 3264

        #4
        Pl;ease remember to use [CODE] tags when posting code.

        MODERATOR

        Just a "by the way," you should learn how to use String.Format for building strings. Either that or System.Text.Str ingBuilder. Because reading long concatenated strings like that is painful, and hard to debug.

        Comment

        • mldisibio
          Recognized Expert New Member
          • Sep 2008
          • 191

          #5
          OK, you are using the actual DetailsView control, which I am not familiar with. Apologies, I thought you meant "details view" in a generic way and might be using a Forms.DataGridV iew with which I am more familiar.

          Hopefully someone with more experience can help you. Nonetheless, sounds like ItemUpdating may be getting called twice...coders familiar with the control know these quirks and will tell you in a heartbeat.

          In the meantime, maybe you could add some Trace statements to the ItemUpdating event handler and see if indeed it is getting called twice. Perhaps (longshot) after executing your sql it fires the updating event again? Try removing the "UPDATE part of your logic, so that it only inserts new records. If you don't get a duplicate, then it might mean it was firing an INSERT followed by an UPDATE for some reason.

          Good luck.

          Comment

          Working...