Hello

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")
        xmlDoc.AppendChild(xmlRoot)

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

        ' 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"))
        xmlHead.AppendChild(xmlTitle)

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

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


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

            ' 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")
                xmlCell.AppendChild(xmlDoc.CreateTextNode(content))
                xmlRow.AppendChild(xmlCell)
            Next
        Next

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.