Venturing into the realm of InfoPath to create a form which will be published to a SharePoint site. I have gone through a lot of learning of creating the form, using secondary connections and filtering its data, and just trying to be able to find a way for the form to dump the information into a SQL table. Probing around I found a solution which is suppose to work, by using a stored procedure to perform the insert and passing through the variables when called for by some button code (found here: http://www.bizsupportonline.net/infopath2007/use-receive-data-connection-execute-sql-server-stored-procedure.htm).
The issue I am having with this solution is that it will trigger the Identity function on a ID column and make the table increment by one, but will not actually insert the record into the table. When I manually call for the Stored Proc passing through the variables, the table captures the data and the tigger increments again just fine. You can see the gap of the "phantom" record from the form in the identity column: 1, 2, 4.
I have tried using simple execute commands, to more involved commands trying to get the new data to stick in the table to no avail. If anyone can offer some advice on the issue, I would greatly appreciate it.
Stored Proceedure:
ALTER PROCEDURE [dbo].[INSERT_MACRO_DSX_ORDER_CLOSER]
@FORM_JOB_NUM varchar(6), @FORM_REP_NAME varchar(50)
WITH EXEC AS CALLER
AS
BEGIN
INSERT INTO WDIS.MACRO.DSX_ORDER_CLOSER (FORM_JOB_NUM, FORM_REP_NAME) VALUES (@FORM_JOB_NUM, @FORM_REP_NAME)
END
Button Code:
' Retrieve the name of the Office application to add to the database table
Dim dom As XPathNavigator = MainDataSource.CreateNavigator()
Dim parmJobNum As String = dom.SelectSingleNode( _
"//my:txtJobNumber", NamespaceManager).Value
Dim parmRepName As String = dom.SelectSingleNode( _
"//my:txtRepName", NamespaceManager).Value
' Retrieve the connection to the database table
Dim connection As AdoQueryConnection = DataConnections("DSX_ORDER_CLOSER")
' Save the original statement that is stored in the Command property
Dim originalCommand As String = connection.Command
' Execute the stored procedure
connection.Command = "BEGIN TRANSACTION DECLARE @FORM_JOB_NUM varchar(6), @FORM_REP_NAME varchar(50) EXEC [dbo].[INSERT_MACRO_DSX_ORDER_CLOSER] @FORM_JOB_NUM = '" & parmJobNum & "', @FORM_REP_NAME = '" & parmRepName & "' COMMIT TRANSACTION "
connection.Execute()
' Restore the statement of the Command property to its original value
connection.Command = originalCommand