Need help with updating repeating table fields using code - InfoPath Dev
in

InfoPath Dev

Need help with updating repeating table fields using code

Last post 04-21-2010 08:07 AM by g21cincy. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 03-31-2010 07:54 AM

    • g21cincy
    • Top 150 Contributor
    • Joined on 10-20-2008
    • Cincinnati, OH
    • Posts 64

    Need help with updating repeating table fields using code

    I have a view in which a user can query data by an account number. The name followed by rows of data (date of transaction, check amount, check number, client), in a repeating table, are displayed underneath the name section. I need to know how to save the data in the repeating table if someone changes a field in the repeating table. I have an update button under the repeating table with the following code. Any help would be greatly appreciated.

    Public Sub UpdateRepeatingTableData_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)

    Dim Nav As XPathNavigator = Me.CreateNavigator()

    Dim Conn As AdoQueryConnection = Me.DataConnections("Unapplied Cash")

    Dim rows As XPathNodeIterator = Nav.Select("/dfs:myFields/dfs:dataFields/d:tblUnappliedCash", NamespaceManager)

    While rows.MoveNext()

    Conn.Command = "UPDATE tblUnappliedCash SET " & _

    "DateOfTransaction ='" & GetValue("/dfs:myFields/dfs:dataFields/d:tblUnappliedCash/@DateOfTransaction", Nav) & "', " & _

    "CKAmount ='" & GetValue("/dfs:myFields/dfs:dataFields/d:tblUnappliedCash/@CKAmount", Nav) & "', " & _

    "CKNumber ='" & GetValue("/dfs:myFields/dfs:dataFields/d:tblUnappliedCash/@CKNumber", Nav) & "', " & _

    "ClientNumber ='" & GetValue("/dfs:myFields/dfs:dataFields/d:tblUnappliedCash/@ClientNumber", Nav) & "' " & _

    "WHERE (FACS_AC = '" & GetValue("/dfs:myFields/dfs:queryFields/q:tblUnappliedCash/@FACS_AC", Nav) & "')"

    Conn.Execute()

    End While

    End Sub

  • 04-07-2010 04:05 PM In reply to

    Re: Need help with updating repeating table fields using code

    Hi -- is there a problem with the current code? Or is it that you need to do this only if a field changes, not if someone clicks the update button?

    Hilary Stoupa

  • 04-08-2010 06:20 AM In reply to

    • g21cincy
    • Top 150 Contributor
    • Joined on 10-20-2008
    • Cincinnati, OH
    • Posts 64

    Re: Need help with updating repeating table fields using code

    I need do this this only if a field changes.

  • 04-08-2010 04:08 PM In reply to

    Re: Need help with updating repeating table fields using code

    Hmmm. But I don't think you'd want to do this on a field changed event, since that may cause more update statements than you really need to run. I guess what I'm trying to understand is if you want to run the update statement any time a field changes in the table, or if when your users click the button you only want to run the update statements if fields have changed.

    You could add another boolean field or attribute to your repeating group, called 'IsChanged' and then set rules on your fields in the repeating group to set that field to true when they change. Then, in your button code you could filter to only get the rows that have changed.

    Looking at your original code, I do see a problem -- you are using absolute XPath to your fields instead of relative. I don't usually use MoveNext, so I'm not familiar with the syntax, but in C# using a foreach, I'd do something like this:

    foreach(XPathNavigator row in rows)
    {
      Conn.Command = "UPDATE tblUnappliedCash SET "  +
      "DateOfTransaction ='" + row.SelectSingleNode("@DateOfTransaction", Nav) + "', " +
      "CKAmount ='" + row.SelectSingleNode("@CKAmount", Nav) + "', " +

      "CKNumber ='" + row.SelectSingleNode("@CKNumber", Nav) + "', " +
      "ClientNumber ='" + row.SelectSingleNode("@ClientNumber", Nav) + "' " +

      "WHERE (FACS_AC = '" + row.SelectSingleNode("@FACS_AC", Nav) + "')"

      Conn.Execute()
    }

    That is just some quick copy/paste pseudo-code, so forgive me any obvious errors, just wanted to give you the idea. Your current code will loop through the rows and keep running update statements for the first values.

    Hilary Stoupa

  • 04-21-2010 08:07 AM In reply to

    • g21cincy
    • Top 150 Contributor
    • Joined on 10-20-2008
    • Cincinnati, OH
    • Posts 64

    Re: Need help with updating repeating table fields using code

    Well I got the update part working fine. Here is the code that I used to get that working.

    Public Sub UpdateRepeatingTableData_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)

    Dim Nav As XPathNavigator = Me.DataSources("Edit Repeating Table").CreateNavigator()

    Dim Conn As AdoQueryConnection = Me.DataConnections("Save Unapplied Cash")

    Dim rows As XPathNodeIterator = Nav.Select("/dfs:myFields/dfs:dataFields/d:tblUnappliedCash", NamespaceManager)

    Dim iCounter As Integer = 1

    While rows.MoveNext()

    Conn.Command = "UPDATE tblUnappliedCash SET " & _

    "DateOfTransaction ='" & GetValue("/dfs:myFields/dfs:dataFields/d:tblUnappliedCash[" & iCounter & "]/@DateOfTransaction", Nav) & "', " & _

    "CKAmount ='" & GetValue("/dfs:myFields/dfs:dataFields/d:tblUnappliedCash[" & iCounter & "]/@CKAmount", Nav) & "', " & _

    "CKNumber ='" & GetValue("/dfs:myFields/dfs:dataFields/d:tblUnappliedCash[" & iCounter & "]/@CKNumber", Nav) & "', " & _

    "ClientNumber ='" & GetValue("/dfs:myFields/dfs:dataFields/d:tblUnappliedCash[" & iCounter & "]/@ClientNumber", Nav) & "' " & _

    "WHERE (UnappliedCashID = '" & GetValue("/dfs:myFields/dfs:dataFields/d:tblUnappliedCash[" & iCounter & "]/@UnappliedCashID", Nav) & "')"

    Conn.Execute()

    iCounter += 1

    End While

    End Sub

     

    Now I would like to have another column to my repeating table where there is a delete button for every row. Do you know how I might go about coding that button?

Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.