Imports Microsoft.VisualBasic
Imports System.Data
Imports
System.Data.OracleClient
Public Class DatasetToXML
Inherits
System.Web.UI.Page
Dim con As New
OracleConnection(" DATA SOURCE=ORACLE;PERSIST
SECURITY INFO=TRUE;USER ID=DF_TRUCK;PASSWORD=DF_TRUCK;UNICODE=TRUE ")
Public Function DS2XML(ByVal
ds As DataSet) As
Boolean
Dim xs As New
System.Xml.XmlWriterSettings
xs.Indent = True
Dim xw As System.Xml.XmlWriter =
System.Xml.XmlWriter.Create(Server.MapPath("~/IEData/abc.xml"),
xs)
xw.WriteStartElement("DF_TRUCK") 'Name
of schema
For Each dt As DataTable In ds.Tables
For
Each dr As
DataRow In ds.Tables(dt.TableName).Rows
xw.WriteStartElement(ds.Tables(dt.TableName).TableName)
For
i As Integer =
0 To ds.Tables(dt.TableName).Columns.Count - 1
xw.WriteElementString(ds.Tables(dt.TableName).Columns(i).ColumnName,
IIf(IsDBNull(dr.Item(i)), String.Empty,
dr.Item(i)))
Next
xw.WriteEndElement()
Next
Next
xw.WriteEndElement()
xw.Flush()
xw.Close()
End Function
End Class
No comments:
Post a Comment