getchanges returns nothing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sam

    #1

    getchanges returns nothing

    Hi,

    Here is my code :

    For Each row As DataRow In m_dsTabs.Tables (0).Rows
    If CInt(row("TabId ")) = DirectCast(tabQ ryTabs.Selected Tab,
    QueryTabPage).T abId Then
    m_dsTabs.Tables (0).Rows.Remove (row)
    Exit For
    End If
    Next
    m_dsTabs.Accept Changes()
    m_dsTabs.GetCha nges(DataRowSta te.Deleted)

    GetChanges returns nothing. Why ? And do you think my method for
    removing a row given a particular TabId (primary key of my table) is a
    good way to do so?

    Thx

  • Armin Zingler

    #2
    Re: getchanges returns nothing

    "Sam" <samuel.berthel ot@voila.fr> schrieb[color=blue]
    > Hi,
    >
    > Here is my code :
    >
    > For Each row As DataRow In m_dsTabs.Tables (0).Rows
    > If CInt(row("TabId ")) = DirectCast(tabQ ryTabs.Selected Tab,
    > QueryTabPage).T abId Then
    > m_dsTabs.Tables (0).Rows.Remove (row)
    > Exit For
    > End If
    > Next
    > m_dsTabs.Accept Changes()
    > m_dsTabs.GetCha nges(DataRowSta te.Deleted)
    >
    > GetChanges returns nothing. Why ?[/color]

    Because you called AcceptChanges, and this removes the deleted rows from the
    table. Afterwards, there are no rows with rowstate=delete d in the table and
    getchanges returns nothing.
    [color=blue]
    > And do you think my method for
    > removing a row given a particular TabId (primary key of my table) is
    > a good way to do so?[/color]


    dim id as integer
    dim row as datarow

    id = DirectCast(tabQ ryTabs.Selected Tab, QueryTabPage).T abId
    row = m_dsTabs.Tables (0).Rows.Find(I D)
    if not row is nothing then row.Delete

    is probably faster (or shorter (or easier)).

    Armin

    Comment

    • Sam

      #3
      Re: getchanges returns nothing

      Thx :)

      Comment

      • Sam

        #4
        Re: getchanges returns nothing

        Actually I've got the error :
        System.Data.Mis singPrimaryKeyE xception - Table doesn't have a primary
        key.
        on that line

        row = m_dsTabs.Tables (0).Rows.Find(T abId)

        TabId is the primary key in my database's table but I don't know how to
        set it to be my primary key in my dataset ??

        Comment

        • Sam

          #5
          Re: getchanges returns nothing

          Ok, I've found out :)

          Dim pk(0) As DataColumn
          pk(0) = m_dsTabs.Tables (0).Columns("Ta bId")
          m_dsTabs.Tables (0).PrimaryKey = pk

          Now it works .

          Thx again

          Comment

          • Sam

            #6
            Re: getchanges returns nothing

            Ok, I've found out :)

            Dim pk(0) As DataColumn
            pk(0) = m_dsTabs.Tables (0).Columns("Ta bId")
            m_dsTabs.Tables (0).PrimaryKey = pk

            Now it works .

            Thx again

            Comment

            • Sam

              #7
              Re: getchanges returns nothing

              Actually I have another problem related to this:

              dt = m_dsTabs.Tables (0).GetChanges( DataRowState.De leted)

              If I try to access dt.Rows(0).Item ("TabID") then I get :

              System.Data.Del etedRowInaccess ibleException - Deleted row information
              cannot be accessed through the row.

              I would have thought that dt would contain the data of the deleted row
              ?
              If not, how can I get this information ?

              Thx

              Comment

              • Cor Ligthert

                #8
                Re: getchanges returns nothing

                Sam,

                Maybe by a

                dt.rejectchange s

                I hope this helps,

                Cor


                Comment

                • Sam

                  #9
                  Re: getchanges returns nothing

                  Thx a lot !

                  Comment

                  Working...