We help IT Professionals succeed at work.
Get Started

XML Output to VB.Net from SQL Stored Procedure

1,752 Views
Last Modified: 2012-09-09
I'm trying to get the XML output from a stored procdure using  FOR XML PATH on my SQL2008 server for use in my VB.NET 2008 application. I can see the Stored procedure executes correctly from SQL Management Studio and VS 2008. I've tried many examples but can't get it to return any data. Please let me know what I'm doing wrong.

My current attempt is:

SqlCmd = New SqlCommand
SqlCmd.CommandText = "CreateD30XML" ' Stored Procedure to Call
SqlCmd.CommandType = CommandType.StoredProcedure
SqlCmd.Parameters.AddWithValue("varJobNo", "415974OC")
SqlCmd.Parameters.AddWithValue("LastMsgID", "")
SqlCmd.Parameters("LastMsgID").Direction = ParameterDirection.Output
SqlCmd.Connection = SQLCon
SqlCmd.ExecuteNonQuery()
MsgBox(SqlCmd.Parameters("LastMsgID").Value)

My Stored Procedure is:

ALTER PROCEDURE  [dbo].[CreateD30XML]
varJobNo As nvarchar(20), @LastMsgID As nvarchar(max) Output

AS
BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;
    -- Insert statements for procedure here
      SELECT  'DeliveredOrderEntry' [@title],
        '441002' [@requestor],            
        HbNo AS [Data/DeliveredOrders/Order/@refnum],
        DLocNo AS [Data/DeliveredOrders/Order/marketname],
        Carrier AS [Data/DeliveredOrders/Order/carriername],
        DName AS [Data/DeliveredOrders/Order/customername],
        DAdr1 AS [Data/DeliveredOrders/Order/customeraddress],
        DCity AS [Data/DeliveredOrders/Order/customercity],
        DState AS [Data/DeliveredOrders/Order/customerstate],
        DZip AS [Data/DeliveredOrders/Order/customerzipcode],
        JETime AS [Data/DeliveredOrders/Order/deliverydate],
        Driver AS [Data/DeliveredOrders/Order/drivername],
        DriverNo AS [Data/DeliveredOrders/Order/driverid],
        JeTime AS [Data/DeliveredOrders/Order/arrivaltimedriver],
        JobNo AS [Data/DeliveredOrders/Order/shipmentid],
        'Delivery' AS [Data/DeliveredOrders/Order/shipmenttype],
        'Box' AS [Data/DeliveredOrders/Order/ordermode],
        'Delivery' AS [Data/DeliveredOrders/Order/ordertype],
        DPhone AS [Data/DeliveredOrders/Order/customerprimaryphonenumber],
        DPhone2 AS [Data/DeliveredOrders/Order/customersecondaryphonenumber],
        '' AS [Data/DeliveredOrders/Order/weekendingdate],
        BANo AS [Data/DeliveredOrders/Order/sellingstore],
        BANo AS [Data/DeliveredOrders/Order/fulfillingstore],
        BANo AS [Data/DeliveredOrders/Order/cfnumber],
        JEndType AS [Data/DeliveredOrders/Order/timepreference],
        '' AS [Data/DeliveredOrders/Order/timewindow]
FROM    JobLogTbl
WHERE   (JobNo = @varJobNo)
FOR     XML PATH('Transaction'),
            ROOT('Request')

END
Comment
Watch Question
Staff Software Engineer
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE