none
Inconsistent DA.update behavior RRS feed

  • Question

  • I have a stubborn table that is not updating as expected. If I change many columns in many rows in the DGV the update seems to update everything BUT the last column/row that I changed. If I change the date columns to calculate the duration columns the table updates as expected. If I change one string column in the DGV nothing happens on update. Kind of hard to debug when there are no errors and getting mixed results.

    I could use from fresh eyeballs on this procedure.

        Private Sub GetHours() ''---------------------------------------------------------------------------------GetHours
            If Not DSet.Tables.Contains("TimeLogTable") Then
                DSet.Tables.Add("TimeLogTable")
            Else
                DSet.Tables("TimeLogTable").Rows.Clear()
            End If
    
            Using SQLConn As New SqlConnection(My.Settings.SQLConn)
                Using TimeLogDA As New SqlDataAdapter("SELECT * FROM timelog WHERE UserName ='" & Username & "'" &
                                                    " AND cast(PaidTimeIn as date) >='" & ShiftPrdStart & "'" &
                                                    " AND Cast(PaidTimeOut as date) <='" & ShiftPrdEnd & "' ORDER BY ActualTimeIn Desc", SQLConn)
                    TimeLogDA.MissingSchemaAction = MissingSchemaAction.AddWithKey
                    TimeLogDA.FillSchema(DSet.Tables("TimeLogTable"), SchemaType.Source)
                    TimeLogDA.Fill(DSet.Tables("TimeLogTable"))
                    TimeLogBS.DataSource = DSet.Tables("TimeLogTable")
                    DGV_Hours.DataSource = TimeLogBS
                    BindNav_TimeLog.BindingSource = TimeLogBS
    
                    For Each TimeLogRow As DataRow In DSet.Tables("TimeLogTable").Rows
                        TimeLogRow("DayName") = CDate(TimeLogRow("ActualTimeIn").ToString).ToString("dddd")
                    Next
    
                    With DGV_Hours
                        .Columns("ActualHours").ReadOnly = True
                        .Columns("PaidHours").ReadOnly = True
                        .Columns("DayName").ReadOnly = True
                    End With
    
                    For Each TimeLogCol As DataGridViewColumn In DGV_Hours.Columns
                        If Not TimeLogCol.ValueType = GetType(DateTime) Then
                            TimeLogCol.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
                        Else
                            TimeLogCol.Width = 130
                        End If
                    Next
    
                End Using
            End Using
    
        End Sub ''------------------------------------------------------------------------------------------------GetHours
    
    
        Private Sub Button_UpdateTimeLog_Click(sender As Object, e As EventArgs) Handles Button_UpdateTimeLog.Click ''Update Timelog
            Using SQLConn As New SqlConnection(My.Settings.SQLConn)
                Using TimeLogDA As New SqlDataAdapter("SELECT * FROM timelog WHERE UserName ='" & Username & "'" &
                                            " AND cast(PaidTimeIn as date) >='" & ShiftPrdStart & "'" &
                                            " AND Cast(PaidTimeOut as date) <='" & ShiftPrdEnd & "' ORDER BY ActualTimeIn Desc", SQLConn)
    
                    Dim TimeLogCB As New SqlCommandBuilder(TimeLogDA)
                    TimeLogBS.EndEdit()
                    TimeLogDA.Update(DSet.Tables("TimeLogTable"))
                End Using
            End Using
    
        End Sub ''----------------------------------------------------------------------------------------------------Update Timelog

     

    Live as if you were going to die today, learn as if you were going to live forever -Mahatma Gandhi


    • Edited by Gtripodi Wednesday, August 16, 2017 4:05 PM
    Wednesday, August 16, 2017 4:04 PM

All replies

  • I figured it out, but I am a bit baffled.

    The "Button_UpdateTimeLog" button above is on a binding navigator. I manually added the button to the control collection and it is not 'bound' so to say to any bindingsource methods (adnew,delete,move.., etc). Placing a button from the toolbar onto the form and pasting the above update code works just fine. What could be happening from the button on the bindingsource? 


    Live as if you were going to die today, learn as if you were going to live forever -Mahatma Gandhi


    Wednesday, August 16, 2017 6:15 PM
  • I am figured this is bugged at this point. For some reason when I put this update sub on a button that is nested in any control (bound or unbound) such as binding nav or toolstrip the DGV just flashes and all values in the datatable revert to previous values, but only sometimes. Putting the sub on a Button control on the form it works fine

    Live as if you were going to die today, learn as if you were going to live forever -Mahatma Gandhi

    Thursday, August 17, 2017 12:22 PM
  • So I am writing this off as a bug.

    Oddly I can have the toolstrip button perform the non-toolstrip button click with the update procedure and it works.

    Also I am unable to login to VS to report the bug because it says my username does not exist, and when I try to create a new user it says my email address already exists.

    Oh well...

        ''Form Button
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Using SQLConn As New SqlConnection(My.Settings.SQLConn)
    
                Using TimeLogDA As New SqlDataAdapter("SELECT * FROM timelog WHERE UserName ='" & Username & "'" &
                                            " AND cast(PaidTimeIn as date) >='" & ShiftPrdStart & "'" &
                                            " AND Cast(PaidTimeOut as date) <='" & ShiftPrdEnd & "' ORDER BY ActualTimeIn Desc", SQLConn)
    
                    Dim TimeLogCB As New SqlCommandBuilder(TimeLogDA)
    
                    TimeLogBS.EndEdit()
                    TimeLogDA.Update(TimeLogTable)
                End Using
            End Using
        End Sub
        ''ToolStrip Button
        Private Sub UpdateTimeLog() Handles Button_UpdateTimeLog.Click
            Button2.PerformClick()
        End Sub


    Live as if you were going to die today, learn as if you were going to live forever -Mahatma Gandhi

    Thursday, August 17, 2017 1:22 PM
  • And Button2 needs to be visible...

    ...That noise you just heard was me throwing the toolstrip into the dumpster...


    Live as if you were going to die today, learn as if you were going to live forever -Mahatma Gandhi

    Thursday, August 17, 2017 2:11 PM
  • Hi Gtripodi,

    It seems that you can resolved your issue now, you think it is a bug and want to report this issue, please

    close your thread by marking your helpful post an answer, and then report this issue by this link:

    https://connect.microsoft.com/continue.aspx?pageType=2&regType=2&cru=%2FVisualStudio%2Ffeedback%2FCreateFeedback.aspx&cu=

    Thanks for your understanding.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, August 21, 2017 8:47 AM
    Moderator
  • Hi Gtripodi,

    Do you resolve the issue? if yes, could you please share your solution and mark it as answer, if not, could you please share a simple demo which could reproduce your issue via OneDrive, we'll try my best find a solution to resolve it.

    Best regards,

    Cole


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, August 25, 2017 5:57 AM
    Moderator