Kelowna web design and hosting

Kelowna web design and web hosting company 1-250-870-3393

Web site updated: 07/26/2007
About us
Web design portfolio

Mission statement
Testimonials
Careers
Contact us
Sitemap

Our services
Kelowna web design

Search engine marketing
Database design
Kelowna web hosting
Support

Free web design tutorials
HTML tutorials
Javascript tutorials
ASP tutorials
Website marketing
Search engine marketing
Flash tutorials

Free web design articles
Web design
Internet business
Computer programming
Advertising & internet marketing
Search engine marketing
Small business startup
Web hosting
Computer hardware

Web designer resources
Kelowna web mail
DNS lookup tool
E-Books
Tutorial XML feeds
Article XML feeds
Search engine marketing Tools


Web Design Tutorials ASP web site design tutorial Reading a database.

Reading a database.


Reading a database. Learn how to display data from a Database.

Displaying data from a database is one of the most common uses of ASP.
Here's some sample code:


<%
Dim Conn
Dim SQLTemp

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.connectionstring =
"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & Server.MapPath("\yourdb.mdb")& ";"
Conn.Open

SQLTemp = "SELECT * FROM yourTable"
set rstemp=Conn.execute(SQLTemp)

Do While Not rstemp.EOF
%>
<%= rstemp.Fields("pID").Value %>:
<%= rstemp.Fields("pSubj").Value %>,
<%= rstemp.Fields("pDate").Value %>,
<%= rstemp.Fields("pText").Value %>
<br>
<%
rstemp.MoveNext
Loop

Conn.Close
Set Conn = Nothing
%>


That was a simple select query.

Here it is broken down: The first two lines declare the variables Conn and SQLTemp. The next six lines open a connection to your database, and get all the rows from the table. The following Do While Not loop lets u display the data inside the row. The next four lines print out the value of each column in that row. The last bit moves to the next row, ends the loop, and closes the connection to the database.

If you decide you want the data ordered by date, you can use the following code in place of the original SQLTemp:

SQLTemp = "SELECT * FROM yourTable ORDER BY pDate"

Adding DESC or ASC to the end of the query as such:

SQLTemp = "SELECT * FROM yourTable ORDER BY pDate DESC"

will change the order the data is sorted in.

Not too hard, was it?

The last bit we'll cover is how to limit the results, and here we'll limit it to showing only the first 30 results:

SQLTemp = "SELECT * FROM yourTable LIMIT 30"


Any combination of these queries can be mixed and match to achieve results you want.

NOTE: Had trouble connecting to the database? Click here.

Rate This Material: Bad 1 2 3 4 5 Excellent
 




Kelowna web design and web hosting
© 2010 www.kagemedia.com
Kelowna web design and development | Kelowna web hosting
Kelowna website marketing | Kelowna database design | Links

Serving:
Kelowna BC - Penticton BC - Vernon BC - Westbank BC - Winfield BC

FREE web design and hosting package.
Win a FREE web design!
We are giving away a completely free web design and web hosting package every month.

Click here for details