Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 03-08-2004, 06:30 PM   #1 (permalink)
rdove
Masked Moderator
 
rdove's Avatar
 
Join Date: May 2002
Location: Indianapolis, IN
Posts: 260
rdove is on a distinguished road
ASP Recordsets

This tutorial is going to cover populating a basic recordset using ASP.

First, you are going to need to determine your connection string. Commonly used databases used with ASP are SQL Server and MS Access, other databases may be used, so you will have to consult google for a connection string example.

This site has a lot of good references for conenction strings:
http://www.able-consulting.com/ADO_Conn.htm

These are some examples of what a connection string might look like. You will also notice that I have already created my ADO Connection object to be used when creating a recordset.


For MS Access:

Code:
Set conn = Server.createobject("ADODB.CONNECTION")

Conn.open = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & Server.MapPath("DB.mdb") & ";" _
& "Jet OLEDB;"
SQL Server:

Code:
Set conn = Server.createobject("ADODB.CONNECTION")

Conn.open = "Driver={SQL Server};" & _ 
            "Server=MyServerName;" & _
            "Database=myDatabaseName;" & _
            "Uid=;" & _
            "Pwd="
This code block will create a recordset for use based on the SQL statement you send.

Code:
Set rs = Server.CreateObject("ADODB.Recordset")
SQL = "Select First_Name, Last_Name from Customer"
rs.open SQL, conn
To gain access to the records in the recordset you might use a loop like the code below. This will output the first and and last name of all the records in the Customer table until the end of the file has been reached. If you notice the rs.MoveNext, this statement is essential in the loop because failing to move to the next record will cause an infinite loop because you will be stuck on the first record.

Code:
While Not rs.EOF
  response.write(rs("First_Name") & " " & rs("Last_Name") & vbcrlf)
  rs.MoveNext
Wend
And finally closing all your recordsets and connections and releasing them from memory.

Code:
rs.close
conn.close
Set rs = Nothing
Set conn = Nothing
This tutorial should give you a basic idea on how a recordset works and how you can create one.

Tutorial written by:
Ryan Wischmeyer, 2004, Indianapolis, IN
__________________
~Ryan

rdove is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
New Tutorials: ASP Strings, and Visual Studio/VB.NET sde Code Newbie News 0 03-25-2004 06:37 PM
New Java and ASP Tutorials sde Code Newbie News 2 03-15-2004 08:02 PM
Php Vs. Asp sde PHP 6 06-06-2003 06:02 PM


All times are GMT -8. The time now is 08:26 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting