retrieve a value from a table and display it on screen

Posted on 2011-10-04
Last Modified: 2012-05-12
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>

Question by:theartha
    LVL 15

    Expert Comment

    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
    LVL 6

    Accepted Solution

    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:

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now