Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: ADO to XML


Message #1 by "Decell, Gary" <gary.decell@S...> on Fri, 12 Jan 2001 11:11:25 -0500
Does anyone know of any good example of using the System.Data.ADO to execute

a stored proc and serialize the date in to an XML Dom object,

I would think you need the system.xml and system.xml.Serialization but I

have not found and examples.



Thanks G.

Message #2 by Scott Guthrie <scottgu@m...> on Sun, 14 Jan 2001 19:34:05 -0800
Hi Gary,



You can convert a DataSet (produced from either the System.Data.SQL Provider

or from the System.Data.ADO Provider) to an XmlDocument by importing the

System.Xml namespace and then creating a new "XmlDataDocument" -- passing

the DataSet as a constructor argument.  For example:



    Dim XmlDoc as XmlDocument

    XmlDoc = New XmlDataDocument(MyDataSet1)



You will then have full XML DOM access to the data.  



Below is an end-to-end scenario demonstration of this (basically I am taking

data from the Northwind database, creating an XmlDocument out of it, and

then binding it to an <asp:xml> server control for display.



Hope this helps,



Scott



----------------------------------------------------------------------------

---------

Visit http://www.asp.net for the latest ASP.NET Information





<%@ Page ContentType="text/xml" %>

<%@ Import Namespace="System.Data" %>

<%@ Import Namespace="System.Data.SQL" %>

<%@ Import Namespace="System.Xml" %>



<script language="VB" runat=server>



    Function GetProductData() As DataSet



      Dim connection as New

SQLConnection("server=localhost;uid=sa;pwd=;database=northwind")

      Dim command as New SQLDataSetCommand("SELECT * FROM Products WHERE

ProductID<8", connection)

    

      Dim dataset As New DataSet()

      command.FillDataSet(dataset, "dataset")

    

      Return dataset



    End Function



    Sub Page_Load(Sender as Object, E as EventArgs)



      Dim DataSet1 as DataSet = GetProductData()

      Dim XmlDoc as XmlDocument = New XmlDataDocument(DataSet1)



      MyXml1.Document = XmlDoc



    End Sub



</script>



<asp:xml id="MyXml1" runat=server/>



-----Original Message-----

From: Decell, Gary [mailto:gary.decell@S...]

Sent: Friday, January 12, 2001 8:11 AM

To: ASP+

Subject: [aspx] ADO to XML





Does anyone know of any good example of using the System.Data.ADO to execute

a stored proc and serialize the date in to an XML Dom object,

I would think you need the system.xml and system.xml.Serialization but I

have not found and examples.



Thanks G.



---

http://www.asptoday.com - the leading site for timely,

in-depth information for ASP developers everywhere.




Message #3 by "Decell, Gary" <gary.decell@S...> on Mon, 15 Jan 2001 09:01:18 -0500
Thanks for the example it works cool, one more question - I am using sql2000

and I am already returning the recordset as XML (for XML AUTO) so when I use

the code to populate the XMLDoc, it messes up the already formated XML.



  any thoughts?



-----Original Message-----

From: Scott Guthrie [mailto:scottgu@m...]

Sent: Sunday, January 14, 2001 10:34 PM

To: ASP+

Subject: [aspx] RE: ADO to XML





Hi Gary,



You can convert a DataSet (produced from either the System.Data.SQL Provider

or from the System.Data.ADO Provider) to an XmlDocument by importing the

System.Xml namespace and then creating a new "XmlDataDocument" -- passing

the DataSet as a constructor argument.  For example:



    Dim XmlDoc as XmlDocument

    XmlDoc = New XmlDataDocument(MyDataSet1)



You will then have full XML DOM access to the data.  



Below is an end-to-end scenario demonstration of this (basically I am taking

data from the Northwind database, creating an XmlDocument out of it, and

then binding it to an <asp:xml> server control for display.



Hope this helps,



Scott



----------------------------------------------------------------------------

---------

Visit http://www.asp.net for the latest ASP.NET Information





<%@ Page ContentType="text/xml" %>

<%@ Import Namespace="System.Data" %>

<%@ Import Namespace="System.Data.SQL" %>

<%@ Import Namespace="System.Xml" %>



<script language="VB" runat=server>



    Function GetProductData() As DataSet



      Dim connection as New

SQLConnection("server=localhost;uid=sa;pwd=;database=northwind")

      Dim command as New SQLDataSetCommand("SELECT * FROM Products WHERE

ProductID<8", connection)

    

      Dim dataset As New DataSet()

      command.FillDataSet(dataset, "dataset")

    

      Return dataset



    End Function



    Sub Page_Load(Sender as Object, E as EventArgs)



      Dim DataSet1 as DataSet = GetProductData()

      Dim XmlDoc as XmlDocument = New XmlDataDocument(DataSet1)



      MyXml1.Document = XmlDoc



    End Sub



</script>



<asp:xml id="MyXml1" runat=server/>



-----Original Message-----

From: Decell, Gary [mailto:gary.decell@S...]

Sent: Friday, January 12, 2001 8:11 AM

To: ASP+

Subject: [aspx] ADO to XML





Does anyone know of any good example of using the System.Data.ADO to execute

a stored proc and serialize the date in to an XML Dom object,

I would think you need the system.xml and system.xml.Serialization but I

have not found and examples.



Thanks G.

Message #4 by "Scott Guthrie" <scottgu@m...> on Mon, 15 Jan 2001 15:04:52 -0800
I just talked with the ADO.NET and SQL teams about this.  It turns out

that in Beta2 there will be a ExecuteXmlReader on SqlCommand and

OleDbCommand.  This function will return an XmlTextReader (with the XML

results of your XML Auto query). 



Hope this helps,



Scott



-----Original Message-----

From: Decell, Gary [mailto:gary.decell@S...]

Sent: Monday, January 15, 2001 6:01 AM

To: ASP+

Subject: [aspx] RE: ADO to XML





Thanks for the example it works cool, one more question - I am using

sql2000

and I am already returning the recordset as XML (for XML AUTO) so when I

use

the code to populate the XMLDoc, it messes up the already formated XML.



  any thoughts?



-----Original Message-----

From: Scott Guthrie [mailto:scottgu@m...]

Sent: Sunday, January 14, 2001 10:34 PM

To: ASP+

Subject: [aspx] RE: ADO to XML





Hi Gary,



You can convert a DataSet (produced from either the System.Data.SQL

Provider

or from the System.Data.ADO Provider) to an XmlDocument by importing the

System.Xml namespace and then creating a new "XmlDataDocument" --

passing

the DataSet as a constructor argument.  For example:



    Dim XmlDoc as XmlDocument

    XmlDoc =3D New XmlDataDocument(MyDataSet1)



You will then have full XML DOM access to the data. 



Below is an end-to-end scenario demonstration of this (basically I am

taking

data from the Northwind database, creating an XmlDocument out of it, and

then binding it to an <asp:xml> server control for display.



Hope this helps,



Scott



------------------------------------------------------------------------

----

---------

Visit http://www.asp.net for the latest ASP.NET Information





<%@ Page ContentType=3D"text/xml" %>

<%@ Import Namespace=3D"System.Data" %>

<%@ Import Namespace=3D"System.Data.SQL" %>

<%@ Import Namespace=3D"System.Xml" %>



<script language=3D"VB" runat=3Dserver>



    Function GetProductData() As DataSet



      Dim connection as New

SQLConnection("server=3Dlocalhost;uid=3Dsa;pwd=3D;database=3Dnorthwind")

      Dim command as New SQLDataSetCommand("SELECT * FROM Products WHERE

ProductID<8", connection)

   

      Dim dataset As New DataSet()

      command.FillDataSet(dataset, "dataset")

   

      Return dataset



    End Function



    Sub Page_Load(Sender as Object, E as EventArgs)



      Dim DataSet1 as DataSet =3D GetProductData()

      Dim XmlDoc as XmlDocument =3D New XmlDataDocument(DataSet1)



      MyXml1.Document =3D XmlDoc



    End Sub



</script>



<asp:xml id=3D"MyXml1" runat=3Dserver/>



-----Original Message-----

From: Decell, Gary [mailto:gary.decell@S...]

Sent: Friday, January 12, 2001 8:11 AM

To: ASP+

Subject: [aspx] ADO to XML





Does anyone know of any good example of using the System.Data.ADO to

execute

a stored proc and serialize the date in to an XML Dom object,

I would think you need the system.xml and system.xml.Serialization but I

have not found and examples.



Thanks G.



---

http://www.asptoday.com - the leading site for timely,

in-depth information for ASP developers everywhere.






Message #5 by "Decell, Gary" <gary.decell@S...> on Tue, 16 Jan 2001 12:26:53 -0500
Is it possible to use the system.xml.serialization to serialize the record

set into the XMLDocument.



-----Original Message-----

From: Scott Guthrie [mailto:scottgu@m...]

Sent: Monday, January 15, 2001 6:05 PM

To: ASP+

Subject: [aspx] RE: ADO to XML





I just talked with the ADO.NET and SQL teams about this.  It turns out

that in Beta2 there will be a ExecuteXmlReader on SqlCommand and

OleDbCommand.  This function will return an XmlTextReader (with the XML

results of your XML Auto query).  



Hope this helps,



Scott



-----Original Message-----

From: Decell, Gary [mailto:gary.decell@S...]

Sent: Monday, January 15, 2001 6:01 AM

To: ASP+

Subject: [aspx] RE: ADO to XML





Thanks for the example it works cool, one more question - I am using

sql2000

and I am already returning the recordset as XML (for XML AUTO) so when I

use

the code to populate the XMLDoc, it messes up the already formated XML.



  any thoughts?



-----Original Message-----

From: Scott Guthrie [mailto:scottgu@m...]

Sent: Sunday, January 14, 2001 10:34 PM

To: ASP+

Subject: [aspx] RE: ADO to XML





Hi Gary,



You can convert a DataSet (produced from either the System.Data.SQL

Provider

or from the System.Data.ADO Provider) to an XmlDocument by importing the

System.Xml namespace and then creating a new "XmlDataDocument" --

passing

the DataSet as a constructor argument.  For example:



    Dim XmlDoc as XmlDocument

    XmlDoc = New XmlDataDocument(MyDataSet1)



You will then have full XML DOM access to the data.  



Below is an end-to-end scenario demonstration of this (basically I am

taking

data from the Northwind database, creating an XmlDocument out of it, and

then binding it to an <asp:xml> server control for display.



Hope this helps,



Scott



------------------------------------------------------------------------

----

---------

Visit http://www.asp.net for the latest ASP.NET Information





<%@ Page ContentType="text/xml" %>

<%@ Import Namespace="System.Data" %>

<%@ Import Namespace="System.Data.SQL" %>

<%@ Import Namespace="System.Xml" %>



<script language="VB" runat=server>



    Function GetProductData() As DataSet



      Dim connection as New

SQLConnection("server=localhost;uid=sa;pwd=;database=northwind")

      Dim command as New SQLDataSetCommand("SELECT * FROM Products WHERE

ProductID<8", connection)

    

      Dim dataset As New DataSet()

      command.FillDataSet(dataset, "dataset")

    

      Return dataset



    End Function



    Sub Page_Load(Sender as Object, E as EventArgs)



      Dim DataSet1 as DataSet = GetProductData()

      Dim XmlDoc as XmlDocument = New XmlDataDocument(DataSet1)



      MyXml1.Document = XmlDoc



    End Sub



</script>



<asp:xml id="MyXml1" runat=server/>



-----Original Message-----

From: Decell, Gary [mailto:gary.decell@S...]

Sent: Friday, January 12, 2001 8:11 AM

To: ASP+

Subject: [aspx] ADO to XML





Does anyone know of any good example of using the System.Data.ADO to

execute

a stored proc and serialize the date in to an XML Dom object,

I would think you need the system.xml and system.xml.Serialization but I

have not found and examples.



Thanks G.




  Return to Index