Hi Shawn,
Here are sample steps (using the Orders table from the SQL Server Northwind
database) to pass a date parameter to a stored procedure that subsequently
returns a dataset that can be consumed by InfoPath.
If possible, I would encourage you to complete these steps as documented so
you can see how this works and then migrate the functionality to your own
application.
- Step A: Create the VB.NET Web Service
1) Create a new VB.NET Web Service named: GetOrdersByDate
2) Add the following code to Service1.asmx:
<WebMethod()> _
Public Function GetOrdersByDate(ByVal myDate As Date) As DataSet
Dim Con As New SqlConnection("Data Source=<Your SQL Server>;Initial
Catalog=Northwind;Integrated Security=SSPI")
Con.Open()
Dim daOrders As New SqlDataAdapter("[GetOrdersByDate]", Con)
Dim PRM As New SqlParameter("@OrdDate", myDate)
daOrders.SelectCommand.Parameters.Add(PRM)
daOrders.SelectCommand.CommandType = CommandType.StoredProcedure
daOrders.SelectCommand.Parameters(0).Direction =
ParameterDirection.Input
Dim dsOrders As New DataSet
daOrders.Fill(dsOrders)
Return dsOrders
End Function
** NOTE: You will need to change <Your SQL Server> noted above in the
connection string to the name of your SQL Server.
3) Compile and save the web service
4) Test the web method by running this in debug mode. Once Service1.asmx is
displayed, click the GetOrdersByDate link, enter: '4/1/1998' in the myDate
field and click the Invoke button. This should return about 4 records.
- Step B: Create the InfoPath solution
1) Create a new InfoPath solution and choose "From Data Connection" and
complete the following screens:
- First screen: Receive Data
- Second screen: Enter the URL to the web service created above (i.e.
http://localhost/service1.asmx - if you created this directly at:
C:\Inetpub\wwwroot)
- Third screen: Select GetOrdersByDate
- Fourth screen: Click Set Sample Value and enter: 1/1/1900
- Fifth screen: Click Finish
2) From the displayed Data Source Task Pane, expand queryFields and drag
"myDate" to the queryFields area on the form
3) Expand dataFields, drag "Table" to the dataFields area on the form and
select the option: Repeating Section with Controls
4) Preview the form and enter: 4/1/1998 as the date and click the Run Query
button - your Repeating Section should be populate with the same 4 records!
I hope this helps!
Best Regards,
Scott L. Heim
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights