Skip to content

Instantly share code, notes, and snippets.

@sanmadjack
Created May 2, 2013 16:16
Show Gist options
  • Save sanmadjack/5503327 to your computer and use it in GitHub Desktop.
Save sanmadjack/5503327 to your computer and use it in GitHub Desktop.
A function to create a string containing the html table representation of a DataSet
Private Function PrintDataSetToHTML(ByRef ds As DataSet) As String
Dim output As New StringBuilder
For Each dt As DataTable In ds.Tables
output.AppendLine("<table>")
output.Append("<caption>")
output.Append(dt.TableName)
output.AppendLine("</caption>")
output.AppendLine("<tr>")
For Each dc As DataColumn In dt.Columns
output.Append("<th>")
output.Append(dc.ColumnName)
output.AppendLine("</th>")
Next
output.AppendLine("</tr>")
For Each dr As DataRow In dt.Rows
output.AppendLine("<tr>")
For Each dc As DataColumn In dt.Columns
output.Append("<td>")
output.Append(dr(dc))
output.AppendLine("</td>")
Next
output.AppendLine("</tr>")
Next
output.AppendLine("</table>")
Next
Return output.ToString
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment