XML data into XMLDataDoc ...help

D

Dave

Hi
I have decided to use the method explained in the first
example here
http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/cpguide/html/cpconsynchronizingdatasetwithxmldatadocume
nt.asp
To try and load data from an xml file into an XMLDataDoc
and then into a SQL Table

however, i'm a newbie to this and the bit i want to know
is how to:
' Add code to populate the DataSet with schema and data.

is there any example code or tutorials out there that can
help me please?

THanks
 
K

Ken Cox [Microsoft MVP]

Hi Dave,

It just means that you should be filling the dataset with something.

Here's some code I modified from the samples to generate a datatable for use
in a dataset:


Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim myDataSet As DataSet = New DataSet
' Add code here to populate the DataSet with schema and data.
myDataSet.Tables.Add(CreateDataSource())
Dim xmlDoc As XmlDataDocument = New XmlDataDocument(myDataSet)
Response.Write(xmlDoc.OuterXml)
End Sub

Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = True
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top