Dataset GetChanges does not see updates

Posted by: c2d3e4 on 8 September 2017, 12:33 pm EST

  • Posted 8 September 2017, 12:33 pm EST

    Normally, I get my dataset from a data adapter and query command and with the Fill method.  The dataset is then bound to the spread. I check for the updates by using something like

    <FONT size=2>

    DS.Tables(0</FONT><FONT size=2>).GetChanges(System.Data.DataRowState.Modified)


    to return a data table.  This works great.

    Now I need to create my dataset with code since I am getting my data on the fly.  For some reason, the dataset is not seeing the changes made on the spread.  Here is an example of the code below.  Can you tell me how to make it to work?  Thanks!

    <SPAN class=kwd>Public Class</SPAN> Form1

    <SPAN class=kwd>Private</SPAN> DS <SPAN class=kwd>As New</SPAN> DataSet

    <SPAN class=kwd>Private Sub</SPAN> Form1_Load(<SPAN class=kwd>ByVal</SPAN> sender <SPAN class=kwd>As Object</SPAN>, <SPAN class=kwd>ByVal</SPAN> e <SPAN class=kwd>As</SPAN> System.EventArgs) <SPAN class=kwd>Handles Me</SPAN>.Load

    <SPAN class=kwd>Dim</SPAN> table1 <SPAN class=kwd>As</SPAN> DataTable
    <SPAN class=kwd>Dim</SPAN> dr <SPAN class=kwd>As</SPAN> DataRow
    <SPAN class=kwd>Dim</SPAN> i <SPAN class=kwd>As Integer</SPAN>

    <SPAN class=cmt>'define table

    table1 = <SPAN class=kwd>New</SPAN> DataTable(<SPAN class=st>"tblParcel"</SPAN>)

    <SPAN class=kwd>Dim</SPAN> colId <SPAN class=kwd>As New</SPAN> DataColumn(<SPAN class=st>"Id"</SPAN>)
    colId.DataType = <SPAN class=kwd>GetType</SPAN>(Int32)

    <SPAN class=kwd>Dim</SPAN> colX <SPAN class=kwd>As New</SPAN> DataColumn(<SPAN class=st>"X"</SPAN>)
    colX.DataType = <SPAN class=kwd>GetType</SPAN>(Int32)

    <SPAN class=kwd>Dim</SPAN> colY <SPAN class=kwd>As New</SPAN> DataColumn(<SPAN class=st>"Y"</SPAN>)
    colY.DataType = <SPAN class=kwd>GetType</SPAN>(Int32)

    <SPAN class=cmt>'add table to DS


    <SPAN class=cmt>'add the datarows to dataset table

    <SPAN class=kwd>For</SPAN> i = 0 <SPAN class=kwd>To</SPAN> 5
    dr = DS.Tables(<SPAN class=st>"tblParcel"</SPAN>).NewRow()
    dr(<SPAN class=st>"Id"</SPAN>) = i
    dr(<SPAN class=st>"X"</SPAN>) = i + 1
    dr(<SPAN class=st>"Y"</SPAN>) = i + 2
    DS.Tables(<SPAN class=st>"tblParcel"</SPAN>).Rows.Add(dr)
    <SPAN class=kwd>Next</SPAN>

    DS.Tables(<SPAN class=st>"tblParcel"</SPAN>).Rows(FpSpread1.ActiveSheet.ActiveRowIndex).EndEdit()

    <SPAN class=cmt>'add dataset to the spread

    FpSpread1.DataSource = DS
    FpSpread1.DataMember = <SPAN class=st>"tblParcel"</SPAN>

    <SPAN class=kwd>End Sub

    Private Sub</SPAN> Button1_Click(<SPAN class=kwd>ByVal</SPAN> sender <SPAN class=kwd>As</SPAN> System.<SPAN class=kwd>Object</SPAN>, <SPAN class=kwd>ByVal</SPAN> e <SPAN class=kwd>As</SPAN> System.EventArgs) <SPAN class=kwd>Handles</SPAN> Button1.Click

    <SPAN class=kwd>Dim</SPAN> DRow <SPAN class=kwd>As</SPAN> DataRow
    <SPAN class=kwd>Dim</SPAN> ftspread1DT <SPAN class=kwd>As</SPAN> DataTable

    ftspread1DT = DS.Tables(<SPAN class=st>"tblParcel"</SPAN>).GetChanges(System.Data.DataRowState.Modified)

    <SPAN class=kwd>If</SPAN> ftspread1DT IsNot <SPAN class=kwd>Nothing Then
    For Each</SPAN> DRow <SPAN class=kwd>In</SPAN> ftspread1DT.Rows
    MessageBox.Show(<SPAN class=st>"Got Changes"</SPAN>)
    <SPAN class=kwd>Next
    MessageBox.Show(<SPAN class=st>"No Changes"</SPAN>)
    <SPAN class=kwd>End If

    End Sub

    End Class</SPAN>
  • Replied 8 September 2017, 12:33 pm EST


    After binding the Spread to the DataSet, you need to call the AcceptChanges method on the DataSet.

  • Replied 8 September 2017, 12:33 pm EST

    Thanks Scotts.  That's what I just found out too.  I should also add the line

    <FONT size=2>

    DS.Tables(</FONT><FONT color=#a31515 size=2>"tblParcel"</FONT><FONT size=2>).Rows(FpSpread1.ActiveSheet.ActiveRowIndex).EndEdit()


    before I check for changes to make sure current editing cell is done with.

    Joe D


Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels