I have a IP 2003 form that is used to request leave time. This form is tied to 2 tables in SQL Server, a parent table (tblPendingLeave) with an Autonumber ID field as the Primary Key and a child table (tblPendingLeaveDetail) with an Autonumber ID field as the Primary Key with ParentID linked to the parent table’s ID field as a Foreign Key. The form’s repeating table data source is tblPendingLeaveDetail. It has its number of rows added programmatically using Visual Studio 2005 vb based on the number of days off requested. So if the employee asks for vacation from 7/16 to 7/18, the vb code inserts 3 detail records where the user can enter additional information for each day.
When the user clicks on the Submit button, the following error is displayed. (I am using an ADODataAdapter to do the submission).
System.Runtime.InteropServices.COMException
InfoPath cannot submit the form.
An error occurred while the form was being submitted.
The parameter is incorrect.
at Microsoft.Office.Interop.InfoPath.SemiTrust.ADOAdapter2.Submit()
at Microsoft.Office.Interop.InfoPath.SemiTrust.ADOAdapterObjectWrapper.Submit()
at LeaveForm.LeaveForm.OnSubmitRequest(DocReturnEvent e)
at Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnSubmitRequest(DocReturnEvent pEvent)
By leaving the form open, I can see that the ParentID field of the first row in the repeating table is filled in correctly but the following rows are not filled in even though I have set the ParentID field to default to the ID field assigned to the new record in tblPendingLeave. If the user clicks on the OK button to close the error message and then clicks on the Submit button again the data is submitted successfully. With the form open, I can see that it has deleted all of the detail rows except for the first one and shows the ParentID of the record that was just inserted into the tblPendingLeave table and the ID of the first record inserted into tblPendingLeaveDetail.
If I remove the code to insert the rows into the repeating table and manually add them, the system will insert the records into the 2 SQL Server tables with no problem.
Below is a portion of the code I have tried. I have tried both the new code and the old code shown below and both give the same problem.
What am I doing wrong?
If CDate(NextDate) <= CDate(toDate) Then 'New code to insert lines into the repeating table thisXDocument.View.ExecuteAction("xCollection::insert", "tblPendingLeaveDetail_7") With thisXDocument.DOMthisXDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:tblPendingLeave/d:tblPendingLeaveDetail[last()]/@LeaveDate").text = NextDate.ToString("yyyy-MM-dd") End With 'Old Code to automatically insert the detail row newChild = thisXDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:tblPendingLeave/d:tblPendingLeaveDetail")cloneNode = newChild.cloneNode(True) thisXDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:tblPendingLeave").appendChild(cloneNode)thisXDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:tblPendingLeave/d:tblPendingLeaveDetail[last()]/@LeaveDate").text = NextDate.ToString("yyyy-MM-dd") End If
The code then adds 1 to the NextDate variable and cycles until it reaches the toDate, which is the Ending Date entered by the user.