473,324 Members | 2,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

How do I output stored procedure to XML?

What amendments to the ASP.NET 3.5. VB code below output the MSSQL stored
procedure dataset result to XML (as a response stream)?

(I also guessing to use Response.ContentType = "text/xml"):
Imports System.Data.SqlClient
Imports System.Data

Partial Class pages_default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

'Output stored procedure result as XML
'--------------------------------------------

Dim sqlConnection1 As New
SqlConnection(sfGeneral.fGetConnectionString())
Dim cmd As New SqlCommand

Dim dr As SqlDataReader = Nothing
cmd.Connection = sqlConnection1
cmd.CommandText = "uspXMLSource"

cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@EnterLanguageCode",
Session("strLanguageSetting"))

Try
sqlConnection1.Open()
dr = cmd.ExecuteReader
If dr.HasRows Then
dr.Read()
End If
Catch ex As SqlException
Throw ex
Finally
sqlConnection1.Close()
sqlConnection1.Dispose()
End Try
End Sub
End Class

Oct 8 '08 #1
2 1777
On Oct 8, 2:27*am, "Mark B" <none...@none.comwrote:
What amendments to the ASP.NET 3.5. VB code below output the MSSQL stored
procedure dataset result to XML (as a response stream)?

(I also guessing to use Response.ContentType = "text/xml"):

Imports System.Data.SqlClient
Imports System.Data

Partial Class pages_default
* * Inherits System.Web.UI.Page

*Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

* * * * 'Output stored procedure result as XML
* * * * '--------------------------------------------

* * * * Dim sqlConnection1 As New
SqlConnection(sfGeneral.fGetConnectionString())
* * * * Dim cmd As New SqlCommand

* * * * Dim dr As SqlDataReader = Nothing
* * * * cmd.Connection = sqlConnection1
* * * * cmd.CommandText = "uspXMLSource"

* * * * cmd.CommandType = CommandType.StoredProcedure
* * * * cmd.Parameters.AddWithValue("@EnterLanguageCode",
Session("strLanguageSetting"))

* * * * Try
* * * * * * sqlConnection1.Open()
* * * * * * dr = cmd.ExecuteReader
* * * * * * If dr.HasRows Then
* * * * * * * *dr.Read()
* * * * * * End If
* * * * Catch ex As SqlException
* * * * * * Throw ex
* * * * Finally
* * * * * * sqlConnection1.Close()
* * * * * * sqlConnection1.Dispose()
* * * * End Try
* * End Sub
End Class
Use DataSet, it can retrieve XML from relational data.

Example:

Dim ds As New dataset
Dim connStr As String = "database=NorthWind;Data
Source=localhost;User id=sa;password=sa"
Using conn As New SqlConnection(connStr)
Dim command As New SqlCommand("select * from customers",
conn)
conn.Open()
ds.DataSetName = "Customers"
ds.Load(command.ExecuteReader(),
LoadOption.OverwriteChanges, "customers")
Response.ContentType = "text/xml"
ds.WriteXml(Response.OutputStream)
End Using

Oct 8 '08 #2
Thanks very much Alexey.
Oct 8 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Steve Holden | last post by:
Has anyone, with any driver whatsoever, managed to retrieve output parameters from a SQL Server stored procedure? I've just been rather embarrassed to find out it's not as easy as it might seem,...
1
by: Bari Allen | last post by:
I have a Stored procedure in SQL, that works, when tested in SQL, with one input & several output parameters, as follows: CREATE PROCEDURE myProcedure @MyID int , @First varchar(80) OUTPUT ,...
2
by: Begoña | last post by:
in my java application I've made a call to this stored procedure CREATE procedure pruebaICM @pANI varchar(20), @pTABLA varchar(20), @pInsert varchar(500), @pUpdate varchar(1000), @pFLAG...
5
by: Jay Chan | last post by:
I am trying to use a command line program to run a stored procedure that generates output in a comma-delimitted format. Somehow, ISQL or OSQL always wrap the lines at 256 characters. I believe this...
4
by: laurenq uantrell | last post by:
I need to get the value of an output parameter back into my VBA function calling a stored procedure. I'm using the following construction to append a new record in a SQL Server table: ...
8
by: Christopher Weaver | last post by:
I'm having trouble accessing the value of an output parameter of a stored procedure. The SP looks like this: SET TERM ^ ; CREATE PROCEDURE SP_NEW_TASK RETURNS ( "uidTask" INTEGER) AS begin
2
by: Bari Allen | last post by:
ASP Classic question: I have a Stored procedure in SQL, that works, when tested in SQL, with one input & several output parameters, as follows: CREATE PROCEDURE myProcedure @MyID int , @First...
5
by: MS | last post by:
Here's my simple stored procedure: ALTER PROCEDURE GetMemberIDByEmail @Email EmailAddress, @ID int OUTPUT AS SELECT @ID = ID FROM tbl_Member WHERE Email=@Email RETURN
4
by: Mr Not So Know It All | last post by:
im new to SQL Server and ASP.Net. Here's my problem. I have this SQL Server stored procedure with an input parameter and output parameter CREATE PROCEDURE . @in_rc varchar(8) @out_eList...
0
by: IamtheEvster | last post by:
Hi All, I am currently using PHP 5 and MySQL 5, both on Fedora Core 5. I am unable to call a MySQL stored procedure that returns output parameters using mysql, mysqli, or PDO. I'm having a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.