retrieve a value from a table and display it on screen

Hi There,

I am newbie to ASP. How can I retrieve a value from a table and display it on my screen?

<iframe width="100%" height="300">
  <p>// display the value here.</p>

Who is Participating?
There are a ton of ways to do this, depending on your database type and personal preferences. here's a simple way to do it with a SQL Server database.

The below, of course, is pretty generic because I have no idea what your DB table looks like or how many rows you're fetching etc. You'll need to customize the SQL connection string to match your situation as well as your SQL query. But hopefully this will give you a good starting point.

' SQL Conneciton string
ThisSQL_Conn = "Driver={SQL Server};Server=(local);Database=YourDBName;uid=YourDBUser;pwd=YourDBPswd"

'Site db connection
Set Con = Server.CreateObject("Adodb.Connection")
Con.Open ThisSQL_Conn

' Open recordset
Set rs = Con.Execute("SELECT Field1,Field2 FROM TableName WHERE Field1 = 'value'")

' Populate vars
MyField1 = rs("Field1")
MyField2 = rs("Field2")

' Display values
<iframe width="100%" height="300">
  <p><%=MyField1%> - <%=MyField2%></p>

Open in new window

Not sure why you're using an iFrame either, but I just put that in there as that is what you showed in your example.

For connection strings on other servers or DBs you can always check:
Please refer to these links for further details on how to fetch data from database table and display on page, as not sure on your preference on coding have provided with both classic ASP and .NET version example, hope this help.

Classic ASP:


Good Luck
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.