ASP
  Home arrow ASP arrow Page 4 - ADO for the Beginner
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

ADO for the Beginner
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 20
    2007-11-12

    Table of Contents:
  • ADO for the Beginner
  • Connecting to a Database
  • Connect to a Database with ODBC
  • Working with Table Recordsets
  • How to Display Data

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    ADO for the Beginner - Working with Table Recordsets


    (Page 4 of 5 )

    Now that we have created a database connection, we can move on to creating a table recordset.

    If we use our ChuckNorrisVictims database as an example, we can access a table in it using the following method. Let's say there is a table called Victims, holding a list of everyone Chuck Norris has brutalized yet allowed to live.


    <%

    set conn=Server.CreateObject("ADODB.Connection")

    conn.Provider="Microsoft.Jet.OLEDB.4.0"

    conn.Open "  c:/website/chucknorrisvictims.mdb  "


    set rs=Server.CreateObject("ADODB.recordset")

    rs.Open "Victims", conn

    %>

    How to Create an Add SQL Recordset

    Another method of accessing our Victims table is to use SQL, like so:


    <%

    set conn=Server.CreateObject("ADODB.Connection")

    conn.Provider="Microsoft.Jet.OLEDB.4.0"

    conn.Open "  c:/website/chucknorrisvictims.mdb  "


    set rs=Server.CreateObject("ADODB.recordset")

    rs.Open "Select * from Victims", conn

    %>

    In the above code sample we use a SQL statement to retrieve a list of data from our Victims table in the ChuckNorrisVictims database.

    How to Retrieve Data from a Recordset

    Let's say we want to extract some data from our Victims table. Now that we have opened the table, we can do so:


    <%

    set conn=Server.CreateObject("ADODB.Connection")

    conn.Provider="Microsoft.Jet.OLEDB.4.0"

    conn.Open "  c:/website/chucknorrisvictims.mdb  "


    set rs.Server.CreateObject(ADODB.recordset")

    rs.Open "Select * from Victims", conn


    for each x ni rs.fields

    response.write(x.name)

    response.write(" = ")

    response.write(x.value)

    next

    %>

    This will return all of the data in the Victims table.

    Now that have retrieved the data, let's display it. We can do this in several different ways.

    More ASP Articles
    More By James Payne


       · Heyo! Welcome to my article on Beginning ADO. Here we discuss such topics as:...
     

    ASP ARTICLES

    - ADO for the Beginner
    - ADO.NET 101: Data Rendering with a DataGrid ...
    - Introducing SoftArtisans OfficeWriter 3.0 En...
    - Getting Remote Files With ASP
    - The Real Basics of Functions in ASP
    - Enhancing Readability with ASP
    - Mimicking PHP's String Formatting Functions
    - Windows Server Hacks 12, 77, and 98
    - How to Sort a Multi-Dimensional Array
    - Developing an Information Management Tool wi...
    - What are Active Server Pages?
    - Getting Remote Pages with ASP
    - FTP’ing Files with ASP
    - Apply Single-Sign-On to Your Application
    - Easy Error Management





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway