Have problems sending data from one repeating table to another. - InfoPath Dev Sign in | Join | Help in SQL Database Integration InfoPath (Entire Site) InfoPath Dev InfoPath Dev is dedicated to bringing you the information and tools you need to be successful in your Microsoft Office InfoPath development projects. Home Blogs Forums Photos Downloads InfoPath Dev » InfoPath » SQL Database Integration » Have problems sending data from one repeating table to another. 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: Oldest to newest Newest to oldest Previous Next 02-16-2011 10:42 AM g21cincy Joined on 10-20-2008 Cincinnati, OH Posts 64 Have problems sending data from one repeating table to another. Reply Contact 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 Patrick Halstead Joined on 08-07-2006 Posts 5,112 Re: Have problems sending data from one repeating table to another. Mark as Not AnswerMark as Answer... Reply Contact 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 HalsteadProject Manager at Qdabra 05-01-2013 07:25 PM In reply to 40andinschool2 Joined on 04-24-2013 Posts 31 Re: Have problems sending data from one repeating table to another. Mark as Not AnswerMark as Answer... Reply Contact 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 Joined on 10-20-2008 Cincinnati, OH Posts 64 Re: Have problems sending data from one repeating table to another. Mark as Not AnswerMark as Answer... Reply Contact 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 40andinschool2 Joined on 04-24-2013 Posts 31 Re: Have problems sending data from one repeating table to another. Mark as Not AnswerMark as Answer... Reply Contact 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 Joined on 10-20-2008 Cincinnati, OH Posts 64 Re: Have problems sending data from one repeating table to another. Mark as Not AnswerMark as Answer... Reply Contact "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 StringDim node As XPathNavigator = Nav.SelectSingleNode(XPath, Me.NamespaceManager) If node Is Nothing Then Return "" ElseReturn node.Value.Replace("'", "''") End If End Function 05-02-2013 12:34 PM In reply to 40andinschool2 Joined on 04-24-2013 Posts 31 Re: Have problems sending data from one repeating table to another. Mark as Not AnswerMark as Answer... Reply Contact 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 Joined on 10-20-2008 Cincinnati, OH Posts 64 Re: Have problems sending data from one repeating table to another. Mark as Not AnswerMark as Answer... Reply Contact 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 40andinschool2 Joined on 04-24-2013 Posts 31 Re: Have problems sending data from one repeating table to another. Mark as Not AnswerMark as Answer... Reply Contact 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 40andinschool2 Joined on 04-24-2013 Posts 31 Re: Have problems sending data from one repeating table to another. Mark as Not AnswerMark as Answer... Reply Contact 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 Joined on 10-20-2008 Cincinnati, OH Posts 64 Re: Have problems sending data from one repeating table to another. Mark as Not AnswerMark as Answer... Reply Contact Try moving the ")" down a line. 05-03-2013 08:42 AM In reply to 40andinschool2 Joined on 04-24-2013 Posts 31 Re: Have problems sending data from one repeating table to another. Mark as Not AnswerMark as Answer... Reply Contact Thank you, that is fixed. Now I have this message when I click the "Copy" button that has the code: System.Collections.Generic.KeyNotFoundExceptionThe 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 = 1While 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 WhileEnd Sub 05-03-2013 09:03 AM In reply to Hilary Stoupa Joined on 06-20-2008 Posts 13,297 Re: Have problems sending data from one repeating table to another. Mark as Not AnswerMark as Answer... Reply Contact 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 40andinschool2 Joined on 04-24-2013 Posts 31 Re: Have problems sending data from one repeating table to another. Mark as Not AnswerMark as Answer... Reply Contact Hilary, Thank you. I capitalized my "C" in the word connection. 05-13-2013 10:33 AM In reply to 40andinschool2 Joined on 04-24-2013 Posts 31 Re: Have problems sending data from one repeating table to another. Mark as Not AnswerMark as Answer... Reply Contact 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 SubPublic 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).ValueDim Color As String = rows.Current.SelectSingleNode("@Color", NamespaceManager).Value Dim OracleNmbr As String = rows.Current.SelectSingleNode("@OracleNmbr", NamespaceManager).ValueDim RevitNme As String = rows.Current.SelectSingleNode("@RevitNme", NamespaceManager).Value Dim Catg As String = rows.Current.SelectSingleNode("@Catg", NamespaceManager).ValueDim CSPK As String = rows.Current.SelectSingleNode("@CSPK", NamespaceManager).Value Dim Selecta As String = rows.Current.SelectSingleNode("@Select", NamespaceManager).Value If Selecta = "True" Then TryDim 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 UsingCatch 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.
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.
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.
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
40andinschool2,
Are you trying to sending data from one repeating table to another like I was trying to do in this post?
Yes, I am trying to do the same thing you accomplished.
"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
"'" & GetValue("/dfs:myFields/dfs:dataFields/d:tblRepeatingTableA[" & iCounter & "]/@Value2", Nav) & "', " & _
Conn.Execute()
' Refresh your DataConnectionB to show that the data has been moved
' I used the function below for the GetValue
Private
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?
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.
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?
I am getting an Identifier Expected error on the last underscore. Any ideas?
"'" & GetValue("/dfs:myFields/dfs:dataFields/d:PartsList[" & iCounter & "]/@Value4", Nav) & "' " & _ ")"
Try moving the ")" down a line.
Thank you, that is fixed. Now I have this message when I click the "Copy" button that has the code:
System.Collections.Generic.KeyNotFoundExceptionThe 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
Conn.Command =
")"
iCounter += 1
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,
Thank you. I capitalized my "C" in the word connection.
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:
node.DeleteSelf()
DeleteNil(node)
writer.WriteElementString(
writer.WriteEndElement()
writer.Close()
MessageBox.Show(ex.Message)