Quickly create HTML tables from an ADO Recordset

Quickly create HTML tables from an ADO Recordset

The ADO Recordset object exposes the GetString method, which returns the values in the Recordset into a formatted string. Here’s its syntax:

res = GetString([StringFormat As StringFormatEnum = adClipString], _    [NumRows As Long = -1], [ColumnDelimeter As String], _    [RowDelimeter As String], [NullExpr As String]) As String

This method is often used to quickly export a Recordset into a comma-delimited file, even though this approach has several flaws (for example, you can’t put quotes around string values).

The GetString method, however, turns to be very handy when generating HTML tables based on an ADO Recordset. The trick is to use the correct delimiters for the table’s cells and rows. Moreover, you must correctly complete the string with the opening tags for the first cell of the first row, and for the last cell of the last row. Here’s an example of how to implement this technique:

Dim rs, tmpSet rs = Server.CreateObject("ADODB.Recordset")rs.Open "publishers", "DSN=pubs"' open the table (you can set all the necessary attributes here)Response.Write "' convert the recordset to a tabletmp = rs.GetString( , , "
", "
", " ")' to complete the conversion you must add the opening TR and TD tags' for the very first cell, and drop the closing TD and TR tags' after the very last cellResponse.Write "
" & Left(tmp, Len(tmp) - 8)' close the tableResponse.Write "
"

Note that you must pass the HTML notation for “space”, that is ” “, in the last argument to GetString. If you don’t do so, Null values will not produce any table cell.

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of