Have problems sending data from one repeating table to another. - InfoPath Dev
in

InfoPath Dev

Have problems sending data from one repeating table to another.

Last post 05-31-2013 02:21 PM by Hilary Stoupa. 42 replies.
Page 1 of 3 (43 items) 1 2 3 Next >
Sort Posts: Previous Next
  • 02-16-2011 10:42 AM

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

    Have problems sending data from one repeating table to another.

    I have 2 repeating tables. Each are from a different table in my SQL database. I can get the data to send from one to the other if there is no date involved but once I throw in a date field for both then it throws a "Conversion failed when converting datetime from character string." The field being sent from Table1 to the field in Table2 are both 'datetime' datatypes.

     Here's the concept on how it works

    Table 1

     Date Added, Name, Dept fields

    Table 2

    Signup Date, Name, Dept, Add Trainee(check box) fields

    Enroll button below Table 2 to move row to Table 1 for any check boxes under Add Trainee checked.

    When the check box is checked and I click the enroll button that row of data should copy to Table 1 and refresh so that it shows up there. Once that happens the row of data that was copied is deleted from Table 2. Date Added just takes the current date. I want Signup Date to copy over to Table 1 even though it's not going to be shown so that if the person is removed from Table 1 back to Table 2 the Signup Date won't be blank.

    Any suggestions would be very much appreciated.

  • 02-18-2011 12:29 AM In reply to

    Re: Have problems sending data from one repeating table to another.

    SQL data types are not the same as InfoPath. In particular a date-time field in SQL is not the same as a date-time field in XML. XML date types are strings of the following format: 2011-02-18T00:27:49. You'll have to convert to that if you want to use date picker control in InfoPath. I recommend just treating them as strings in the InfoPath form when you are displaying. When you need to enter the date time, you can have a separate date time picker that is bound to the field.

    Patrick Halstead
    Project Manager at Qdabra
  • 05-01-2013 07:25 PM In reply to

    Re: Have problems sending data from one repeating table to another.

    Cincy,

     I am having problems sending data from one SQL table to another SQL table.  Can you pleae attach a copy of your template showing how you were able to do this?  I have been trying to figure this out for going on 4 weeks.

    Thank you - Chad

  • 05-02-2013 07:04 AM In reply to

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

    Re: Have problems sending data from one repeating table to another.

    40andinschool2,

    Are you trying to sending data from one repeating table to another like I was trying to do in this post?

  • 05-02-2013 08:02 AM In reply to

    Re: Have problems sending data from one repeating table to another.

    Cincy,

    Yes, I am trying to do the same thing you accomplished.

    Thank you - Chad

  • 05-02-2013 10:01 AM In reply to

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

    Re: Have problems sending data from one repeating table to another.

    "DataConnectionA": Repeating Table A  (tblRepeatingTableA) where data is coming from is bound to this data connection

    "DataConnectionB": Repeating Table B (tblRepeatingTableB) where data is being sent to from Repeating Table A

    "DataConnectionB_AddNew": Data Connection that will send data from Table A  (tblRepeatingTableA) to Table B (tblRepeatingTableB). Bind this connection to tblRepeatingTableB

    * If you are including dates in this data connection make sure you convert all of them using the following "Convert(VARCHAR(25), VariableDate, 121) AS VariableDate" in your select statement of that data connection otherwise you will get the error about the date conversion

     

    Dim Nav As XPathNavigator = Me.DataSources("DataConnectionA").CreateNavigator() 

    Dim Conn As AdoQueryConnection = Me.DataConnections("DataConnectionB_AddNew")    

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

    Dim iCounter As Integer = 1

    While rows.MoveNext()

    Conn.Command = "INSERT INTO tblRepeatingTableB (ValueOne, ValueTwo, ValueThree, ValueFour) VALUES(" & _

    "'" & GetValue("/dfs:myFields/dfs:dataFields/d:tblRepeatingTableA[" & iCounter & "]/@Value1", Nav) & "', " & _

    "'" & GetValue("/dfs:myFields/dfs:dataFields/d:tblRepeatingTableA[" & iCounter & "]/@Value2", Nav) & "', " & _

    "'" & GetValue("/dfs:myFields/dfs:dataFields/d:tblRepeatingTableA[" & iCounter & "]/@Value3", Nav) & "', " & _

    "'" & GetValue("/dfs:myFields/dfs:dataFields/d:tblRepeatingTableA[" & iCounter & "]/@Value4", Nav) & "' " & _     'Make sure there is no comma at the end like the previous three shown here do

    ")"

    Conn.Execute()

    iCounter += 1

    End While

    ' Refresh your DataConnectionB to show that the data has been moved

    ' I used the function below for the GetValue

    Private Function GetValue(ByVal XPath As String, ByVal Nav As XPathNavigator) As String

    Dim node As XPathNavigator = Nav.SelectSingleNode(XPath, Me.NamespaceManager)

    If node Is Nothing Then

    Return ""

    Else

    Return node.Value.Replace("'", "''")

    End If

    End Function

  • 05-02-2013 12:34 PM In reply to

    Re: Have problems sending data from one repeating table to another.

    Thank you. I am working on the first parts of this.  Here is a really novice question.  Where is this code placed?  Is it an on load event or behind a custom button?

     

  • 05-02-2013 12:55 PM In reply to

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

    Re: Have problems sending data from one repeating table to another.

    In the project that I used this for I put it behind a button. However, in my project I had a checkbox at the end of each row to be able to select which rows of data to move. You would need an If Then statement checking each row before the SQL connection executes.

  • 05-02-2013 01:18 PM In reply to

    Re: Have problems sending data from one repeating table to another.

    Thank you.  I am putting it behind a button for now but the ultimate goal is to get the check boxes (baby steps). How were you able to call the function from the sub?

  • 05-02-2013 01:27 PM In reply to

    Re: Have problems sending data from one repeating table to another.

     I am getting an Identifier Expected error on the last underscore.  Any ideas?

     "'" & GetValue("/dfs:myFields/dfs:dataFields/d:PartsList[" & iCounter & "]/@Value4", Nav) & "' " & _ ")"

  • 05-03-2013 05:27 AM In reply to

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

    Re: Have problems sending data from one repeating table to another.

    Try moving the ")" down a line.

  • 05-03-2013 08:42 AM In reply to

    Re: Have problems sending data from one repeating table to another.

    Thank you, that is fixed.  Now I have this message when I click the "Copy" button that has the code:

     System.Collections.Generic.KeyNotFoundException
    The given key was not present in the dictionary.
       at System.ThrowHelper.ThrowKeyNotFoundException()
       at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
       at Microsoft.Office.InfoPath.Internal.DataConnectionsHost.get_Item(String name)
       at Bridge_22Apr13.FormCode.CTRL174_23_Clicked(Object sender, ClickedEventArgs e)
       at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
       at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)

    The code behind the button is:

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

    Dim Nav As XPathNavigator = Me.DataSources("PartsList").CreateNavigator()

    Dim Conn As AdoQueryConnection = Me.DataConnections("Main Connection")

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

    Dim iCounter As Integer = 1

    While rows.MoveNext()

    Conn.Command = "INSERT INTO Main Connection (ValueOne, ValueTwo, ValueThree, ValueFour) VALUES(" & _

    "'" & GetValue("/dfs:myFields/dfs:dataFields/d:PartsList[" & iCounter & "]/@Value1", Nav) & "', " & _

    "'" & GetValue("/dfs:myFields/dfs:dataFields/d:PartsList[" & iCounter & "]/@Value2", Nav) & "', " & _

    "'" & GetValue("/dfs:myFields/dfs:dataFields/d:PartsList[" & iCounter & "]/@Value3", Nav) & "', " & _

    "'" & GetValue("/dfs:myFields/dfs:dataFields/d:PartsList[" & iCounter & "]/@Value4", Nav) & "' " & _

    ")"

    Conn.Execute()

    iCounter += 1

    End While

    End Sub


     

  • 05-03-2013 09:03 AM In reply to

    Re: Have problems sending data from one repeating table to another.

     Is your data source named "PartsList" with no spaces? The error is probably from one of these two lines:

    Dim Nav As XPathNavigator = Me.DataSources("PartsList").CreateNavigator()

    Dim Conn As AdoQueryConnection = Me.DataConnections("Main Connection") 

    Know how to run your code in debug? Here's short post on that - put a break point on these lines so you can see what's up.

    Hilary Stoupa

  • 05-03-2013 10:20 AM In reply to

    Re: Have problems sending data from one repeating table to another.

    Hilary,

    Thank you.  I capitalized my "C" in the word connection.

  • 05-13-2013 10:33 AM In reply to

    Re: Have problems sending data from one repeating table to another.

    I wasn't able to get the other suggestions working for me, however; I did get this to work:  That is only the first step and I am really stumped on the last step.  Does anyone have the "elusive" answer on how to accomplis this?

     

    I have an infoPath form connected to an Access database.  I am ultimately trying to copy from the "PartsList" secondary repeating table to the "POG_MasterList_Infopath"  main submit/retrieve repeating table.

    Here is my working code to copy from the "PartsList" secondary data source to the "PartsListUpdate" secondary data source:

     

    Private Sub DeleteNil(ByVal node As XPathNavigator)

    If (node.MoveToAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance")) Then

    node.DeleteSelf()

    End If

    End Sub

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

    Dim Nav As XPathNavigator = Me.DataSources("PartsList").CreateNavigator()

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

    While rows.MoveNext()

    Dim PartNumb As String = rows.Current.SelectSingleNode("@PartNumb", NamespaceManager).Value

    Dim PartDesc As String = rows.Current.SelectSingleNode("@PartDesc", NamespaceManager).Value

    Dim Color As String = rows.Current.SelectSingleNode("@Color", NamespaceManager).Value

    Dim OracleNmbr As String = rows.Current.SelectSingleNode("@OracleNmbr", NamespaceManager).Value

    Dim RevitNme As String = rows.Current.SelectSingleNode("@RevitNme", NamespaceManager).Value

    Dim Catg As String = rows.Current.SelectSingleNode("@Catg", NamespaceManager).Value

    Dim CSPK As String = rows.Current.SelectSingleNode("@CSPK", NamespaceManager).Value

    Dim Selecta As String = rows.Current.SelectSingleNode("@Select", NamespaceManager).Value

    If Selecta = "True" Then

    Try

    Dim node As XPathNavigator = MainDataSource.CreateNavigator().SelectSingleNode( _"/dfs:myFields/my:Contain/my:PartsListUpdate", NamespaceManager)

    DeleteNil(node)

    Dim myNamespace As String = NamespaceManager.LookupNamespace("my")

    Using writer As XmlWriter = MainDataSource.CreateNavigator().SelectSingleNode( _

    "/dfs:myFields/my:Contain", NamespaceManager).AppendChild()

    writer.WriteStartElement("PartsListUpdate", myNamespace)

    writer.WriteElementString("PartNumb", myNamespace, PartNumb)

    writer.WriteElementString("PartDesc", myNamespace, PartDesc)

    writer.WriteElementString("Color", myNamespace, Color)

    writer.WriteElementString("OracleNmbr", myNamespace, OracleNmbr)

    writer.WriteElementString("RevitNme", myNamespace, RevitNme)

    writer.WriteElementString("Catg", myNamespace, Catg)writer.WriteElementString("CSPK", myNamespace, CSPK)

    writer.WriteEndElement()

    writer.Close()

    End Using

    Catch ex As Exception

    MessageBox.Show(ex.Message)

    End Try

    End If

    End While

    End Sub

Page 1 of 3 (43 items) 1 2 3 Next >
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.