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

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • User (Old forums)
    Post count: 23064
    #16672 |

    I’ve been working on this for 3 days and have searched the forums but can not find a solution.

     I have a Master / Detail Custom grid, where I define an Edit button and Delete button for each line of each of the grids.

    I am able to populate both grids as expected. I use one Dataset (dsdataset1) and have both of the sqladapters populate this dataset. 

                     sqldataadapter1.fill(dsdataset1) ” populates using select * from table1 where id = @id

                     sqldataadapter2.fill(dsdataset1) ” populates using select * from table2 where id = @table1id

                     I have defined a relation between the two tables named relationtable1_table2

                     The master grid is defined as having  a datasource of dsdataset1 and datamember of Table1

                     The detail grid is defined as having a datasource of nothing and datamember of relationtable1_table2

    My grids display fine. I am also able to make changes to the grids and it looks and works as expected.

    However, as soon as I go to a new record and then go back to redisplay the old record and it’s grid, it reverts to the original data (before changes).

    How can I get the changes made in the grid to update the actual data tables. There has got to be something simple that I’m missing.


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

    User (Old forums)
    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
                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
                            End If
                    End If
                End If

            changesDataSet = DsComments1.GetChanges()

            If Not changesDataSet Is Nothing Then


            End If

        End Sub

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

    User (Old forums)
    Post count: 23064

    Hi Greg,

    Can you share the code snipplet tat you used to populate the master and detail grid…. i have been trying for this and it worked only once, i dont know what link i am missing on, but it never worked thereafter.

    Also Should primarykey/foreign key relationship already exist in database & Should the  field names in the database for the primary key / foreign key the same in database.

    I am able to populate 2 datasource ….. but not able to display in grid….. Can you help me with that.




    Imported from legacy forums. Posted by Credits (had 933 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.