dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: SQL, ASP, and Database

  1. #1
    Danielle Guest

    SQL, ASP, and Database


    I need to create an ASP document that will display the results of the following
    SQL statement:

    Select FirstName, LastName, Salary
    From EmployeeInfo
    Where Age > 50
    Order By Salary Asc


    The DSN name is Employee which will be used to connect to the Employee database
    which contains the table EmployeeInfo.

    HELP!!


  2. #2
    Cam Guest

    Re: SQL, ASP, and Database


    "Danielle" <aquagrl_98@yahoo.com> wrote:
    >
    >I need to create an ASP document that will display the results of the following
    >SQL statement:
    >
    >Select FirstName, LastName, Salary
    > From EmployeeInfo
    >Where Age > 50
    > Order By Salary Asc
    >


    >
    >The DSN name is Employee which will be used to connect to the Employee database
    >which contains the table EmployeeInfo.
    >
    >HELP!!
    >

    Hi Danielle,

    Using VBscript in ASP:

    <%@ LANGUAGE="VBSCRIPT" %>
    <html>
    *connect to database*
    <%
    Set cnEmployee = Server.CreateObject("ADODB.Connection")
    cnEmployee.Open "DSN=Employee; UID=*useridgoeshere*; PWD=*passwordgoeshere*;
    database=Employee"
    %>

    <%
    *assign variable to SQL query string
    strSQL = "Select FirstName, LastName, Salary, Age
    > FROM EmployeeInfo WHERE (Age > 50) Order By Salary Asc"

    %>

    <%
    *setup recordset variable and open
    Set rsEmployee = Server.CreateObject("ADODB.Recordset")
    rsEmployee.Open strSQL, cnEmployee, 1, 3
    %>

    <body>
    <%
    *setup loop to display records
    Do Until rsEmployee.EOF
    %>
    *display results in html or other on web page probably in a table
    <table>
    <tr>
    <td><%=rsEmployee("Firstname")%></td>
    <td><%=rsEmployee("Lastname")%></td>
    <td><%=rsEmployee("Salary")%></td>
    </tr>
    </table>

    <%
    ' Close the loop iterating records
    rsEmployee.MoveNext
    Loop
    rsEmployee.Close
    %>
    </body>
    *close connection and clear variables
    cnEmployee.Close
    set cnEmployee = Nothing
    set rsEmployee = Nothing
    </html>

    Hope that helps, there are various ways of doing it but basically ya need
    to connect to database, setup recordset, populate with SQL query, display
    results, close connection.

    Kay
    Cheers
    Cam




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center