Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: VB
Expertise: Beginner
Nov 8, 2005

A Quick Way to Display Text from a Database in ASP

Suppose you are creating a dynamic page in ASP. Most of the page elements are dynamic and you need a few of the headers to have the first letter of each work to be capitalized. With a very small amount of CSS, you can avoid using VBScript for string manipulation. Using text-transform:capitalize you can apply a quick style to any database driven data.

'Create the variables
Dim Conn, RS, SQL

'Set your connection and recordset
Set Conn = Server.CreateObject("ADODB.Connection") 
Set RS = Server.CreateObject("ADODB.Recordset")

'Set the DSN of the connection
Conn.Open "DSN=myODBC"

'create the SQL string
SQL = "Select TopicTitle From Topics Where ID > 0"

'Open the recordset and make it read-only
RS.Open (SQL), Conn,1,1

'loop through recordset
if not RS.EOF then %>

<!-- The "style" attribute of the DIV tag holds the CSS that will transform the text. -->
<div style="text-transform:capitalize"><%=TopicTitle%></div><br>

'end IF statement and cleanup database info
end if 

Set RS = Nothing
Set Conn = Nothing
Ken Pendergast
Thanks for your registration, follow us on our social networks to keep up-to-date