Home Forums WinForms controls Xceed Grid for WinForms Can’t get grid to update database Reply To: Can’t get grid to update database

User (Old forums)
Member
Post count: 23064

I figured it out. Here is what I had to do.

On an event that changes records or on the formclosing event I run this subroutine.

Private Sub SaveChanges()
        Dim changesDataSet As DataSet
        Dim gridrow As Xceed.Grid.DataRow
        Dim detailrow As Xceed.Grid.DataRow

        sqldataadapter1.InsertCommand.CommandText = “” & _
            ” INSERT INTO table1 ” & _
            ”        ( f1, f2, f3, f4, f5, f6) ” & _
            ” VALUES (@f1, @f2, @f3, @f4, @f5, @f6) “

        sqldatadapter1.UpdateCommand.CommandText = “” & _
            ” UPDATE    table1 ” & _
            ” SET ” & _
            ”    f1 = @f1, ” & _
            ”    f2= @f2, ” & _
            ”    f3= @f3, ” & _
            ”    f4= @f4, ” & _
            ”    f5= @f5, ” & _
            ”    f6= @f6, ” & _
             ” WHERE (f1 = @f1)”

        For Each gridrow In Grid.DataRows
            gridrow.EndEdit()
            If gridrow.DetailGrids.Count > 0 Then
                If gridrow.DetailGrids(0).DataRows.Count > 0 Then
                    For Each detailrow In gridrow.DetailGrids(0).DataRows
                        If detailrow.IsBeingEdited Then
                            detailrow.EndEdit()
                        End If
                    Next
                End If
            End If

        Next
      
        changesDataSet = DsComments1.GetChanges()

        If Not changesDataSet Is Nothing Then
            sqldataadapter1.Update(dsdataset1)
            sqldataadapter2.Update(dsdataset1)

            dsdataset1.AcceptChanges()
            buildgrid()

        End If

    End Sub

Imported from legacy forums. Posted by Greg (had 560 views)