Discussion Locked

How to query a database from a web page?

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
Wanting to get some direction on how to build a web page that accesses an access database. Also, on this web page, I need to create a report with a time it takes to complete a certain tasks. This number (time) needs to exlude weekends. Can I use the"workday" feature for this.

5 replies

by andrew

An easy way is to use ASP. Here's an entire ASP page that reads data from an Access DB and generates a web page:

<%@ Language=VBScript %>
<%Option Explicit%>

<%
Dim sDSN
Dim oCon
Dim oRS

on error resume next
sDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:db1.mdb;"
Set oCon = Server.CreateObject("ADODB.Connection")
Set oRS = Server.CreateObject("ADODB.Recordset")

oCon.Open sDSN
oRS.Open "SELECT * FROM Table1", oCon
Do
Response.Write oRS.Fields("Name").Value & " " & oRS.Fields("Status").Value & "
"
oRS.MoveNext
Loop until oRS.EOF
%>

Here'sa link to more about ASP:
http://msdn.microsoft.com/asp

by andrew

In answer to your second question, you can use the DateDiff() function. The built-in weekday function doesn't work, so here's an algorithm that returns the weekday interval between 2 dates:

Function DateDiffW(BegDate, EndDate)
Const SUNDAY = 1
Const SATURDAY = 7
Dim NumWeeks As Integer

If BegDate > EndDate Then
DateDiffW = 0
Else
Select Case Weekday(BegDate)
Case SUNDAY: BegDate = DateAdd("d", 1, BegDate)
Case SATURDAY: BegDate = DateAdd("d", 2, BegDate)
End Select
Select Case Weekday(EndDate)
Case SUNDAY: EndDate = DateAdd("d", -2, EndDate)
Case SATURDAY: EndDate = DateAdd("d", -1, EndDate)
End Select
NumWeeks = DateDiff("ww", BegDate, EndDate)
DateDiffW = NumWeeks * 5 + Weekday(EndDate) - Weekday(BegDate)
End If
End Function

This discussion is closed to new replies.