My first post here.
I'm trying to create a dynamic html page from vb.net.

Here is my code. I get the error "'DataTable' is a type and cannot be used as an expression"
Do you know how to solve this :

' Create a new XML document.
        Dim xmlDoc As XmlDocument = New XmlDocument

        ' Create the html tag.
        Dim xmlRoot As XmlElement = xmlDoc.CreateElement("html")

        ' Create the head tag and append it under the html element.
        Dim xmlHead As XmlElement = xmlDoc.CreateElement("head")

        ' Create the title tag, set it's text to "Database Table"
        ' and append it under the head element.
        Dim xmlTitle As XmlElement = xmlDoc.CreateElement("title")
        xmlTitle.AppendChild(xmlDoc.CreateTextNode("Database Table"))

        ' Create the body element and append it to the root.
        Dim xmlBody As XmlElement = xmlDoc.CreateElement("body")

        ' Create the table and append it.
        Dim xmlTable As XmlElement = xmlDoc.CreateElement("table")

        ' Create the rows.
        For Each row As DataRow In DataTable
            Dim xmlRow As XmlElement = xmlDoc.CreateElement("tr")

            ' Create the cells.
            For Each item As Object In row
                Dim content As String = ""
                If IsDBNull(item) = False Then content = CStr(item)
                Dim xmlCell As XmlElement = xmlDoc.CreateElement("td")

From the code you have posted here you haven't declared a DataTable at all. You have simply decided to use one in this line

For Each row As DataRow In DataTable

But this isn't an instance of a DataTable, its a type. Before you can use the For Each you need to declare the DataTable and fill it with data.

This article has been dead for over six months. Start a new discussion instead.