Display column information: dataset from xml file : XML DataSet « XML « ASP.Net






Display column information: dataset from xml file

<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.SqlClient" %>

<html>
  <head>
    <title>Display Column Information</title>
  </head>
</html>

<script language="VB" runat="server">
Sub Page_Load(Source As Object, E As EventArgs)

  ' Create dataset and data adapter with properties that apply to all tables
  Dim objDataSet As New DataSet("EmployeePage")

  ' First Table - "Comments Table" From XML
  objDataSet.ReadXmlSchema(Server.MapPath("Comments.xsd"))
  objDataSet.ReadXml(Server.MapPath("Comments.xml"))

  ' Diagnostic print of tables in objDataSet - loop through DataSet.Tables
  Dim strNames As String
  Dim c As DataColumn
  Dim iTableItem As DataTable
  For Each iTableItem In objdataSet.Tables
    strNames &= "Table Name: " & iTableItem.tableName & "<br/>"

    For Each c In iTableItem.Columns
      strNames &= "- Column " & c.ColumnName & " is of type " _
                              & c.DataType.ToString & "<br/>"
    Next

  Next
  Response.Write(strNames)
End Sub
</script>


<%-- Comments.xsd
<?xml version="1.0" standalone="yes"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
  <element name="Reviews">
    <complexType>
      <choice maxOccurs="unbounded">
        <element name="Review">
          <complexType>
            <sequence>
              <element name="ReviewID"    type="int" />
              <element name="ProductName" type="string" />
              <element name="EmployeeID"  type="int" />
              <element name="Date"        type="date" />
              <element name="Comment"     type="string" />
            </sequence>
          </complexType>
        </element>
      </choice>
    </complexType>
  </element>
</schema>

--%>


<%-- Comments.xml
<?xml version="1.0" standalone="yes"?>
<Reviews>
  <Review>
    <ReviewID>1</ReviewID>
    <ProductName>Name</ProductName>
    <EmployeeID>6</EmployeeID>
    <Date>2001-01-01</Date>
    <Comment>
      comment
    </Comment>
  </Review>
</Reviews>
--%>
           
       








Related examples in the same category

1.Modify XML data set
2.Load xml data to DataSet
3.Load XML data into DataSet