Create data.xml from a dataset

Feb 19, 2008 at 8:54 PM
Edited Feb 20, 2008 at 2:24 PM
Hello, very nice slideshow. It would be a lot better if you could create the data.xml from a dataset. If anyone knows how to do this could you fill me and the rest of us in on the method. I've started to make this but am having issues getting the data formatted correctly in the data.xml. This task shouldn't be too hard for you veterans out there...
Feb 20, 2008 at 10:50 AM
Take a look at Makes it from two data tables.
Feb 20, 2008 at 2:26 PM
Edited Feb 22, 2008 at 10:40 PM
Ok, this is how I got to work from a dataset while creating the data.xml on the fly:

Dim objConn As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("TESTConnectionString").ToString)

Dim objDS As New DataSet
objDS.DataSetName = "data"

Dim objaCmd As SqlCommand = New SqlCommand("Get_Albums", objConn)
objaCmd.CommandType = CommandType.StoredProcedure
Dim objaDA As New SqlDataAdapter(objaCmd)


objaDA.Fill(objDS, "album")

Dim objsCmd As SqlCommand = New SqlCommand("Get_Slides", objConn)
objsCmd.CommandType = CommandType.StoredProcedure
Dim objsDA As New SqlDataAdapter(objsCmd)

objsDA.Fill(objDS, "slide")


Dim primarykey As DataColumn = objDS.Tables("album").Columns("albumiD")
Dim foreignkey As DataColumn = objDS.Tables("slide").Columns("albumiD")

Dim relation As DataRelation = objDS.Relations.Add(primarykey, foreignkey)
relation.Nested = True

Dim album As DataColumn
For Each album In objDS.Tables("album").Columns
album.ColumnMapping = MappingType.Attribute

Dim slide As DataColumn
For Each slide In objDS.Tables("slide").Columns
slide.ColumnMapping = MappingType.Attribute

objDS.WriteXml(Server.MapPath("data.xml"), XmlWriteMode.IgnoreSchema)

Catch ex As SqlException
lblErrorMessage.Text = ex.ToString()
End Try

***************************Tables and SPROCs*********************

table: album
albumId, title, description, image

table: slide
slideId, albumId, title, description, image, thumbnail

stored procedure: Get_Albums
SELECT albumid, title, description, image FROM album

stored procedure: Get_Slides
SELECT slideId, albumId, title, description, image, thumbnail FROM slide
Feb 20, 2008 at 2:32 PM
Edited Feb 22, 2008 at 10:41 PM

boryto wrote:
Take a look at Makes it from two data tables.

Yes, this works great as well. Unfortunatly some hosting providers charge extra to make a folder set as an application in IIS. Creating from the dataset works well with out this requirement.