Creating a News management system (Part 4)

Below is the code for our page 'display_news.asp' which will display the records in our table 'tblNews'. The code is all documented and explained. Remember this is the only front end file that we intend our visitors to see.

'Display_news.asp'

<%@ Language="VBScript" %>
<% Option Explicit %>
<html>
<head><title>News</title>
</head>
<body>
<div align="center">Basic News Management System</div>
<%
'declare your variables
Dim Connection, sConnString, SQL, Recordset

'declare SQL statement that will query the database
SQL = "SELECT * FROM tblNews"

'create ADO connection and recordset object
Set Connection = Server.CreateObject("ADODB.Connection")
Set Recordset = Server.CreateObject("ADODB.Recordset")

'define connection string, specify database driver and location of database
sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("db/news.mdb")

'Open the connection to the database
Connection.Open(sConnString)

'Open recordset object executing the SQL statement & returning the records
Recordset.Open SQL, connection

'Check to see if there are any records with the End of File (EOF) property
If recordset.Eof Then
Response.write "<br>Sorry there is no current new."
Else
'As there are records lets loop through the records until we come to the end
Do while not recordset.Eof
response.write recordset("headline") & "<br>"
response.write recordset("news_story") & "<br>"
response.write recordset("story_date") & "<br><br>"
'move on to the next record
recordset.movenext
Loop
End If

'We are done so lets close the connection and the recordset
recordset.Close
Set recordset = Nothing
connection.Close
Set connection = Nothing
%>
</body>
</html>

Save the page in the 'news' folder. We will now set up a form to enter news stories to our database.

<<Previous

Get the best asp web hosting provider now and save 30%

Advertisements



MembersPro

MembersPro PayPal - ASP Membership software

Plug and play ASP membership script that integrates with PayPal to let you charge recurring membership fees.

Free ASP Hosting