早期 ASP 時代的經典教程,示範如何使用 VBScript 搭配 SQL Server 構建月視圖日程表,支援月份翻頁、事件增刪,並封裝資料庫連接實現配置集中管理。
<%@ LANGUAGE="VBscript" ENABLESESSIONSTATE = False %>
<%
Option Explicit
Response.Buffer = True
Response.Expires = 0
sub Dochunfeng(strtitle)
%>
<html><head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
<title>星河影動之精英日程安排<%= strtitle %></title>
</head><body bgcolor="white" link="blue" alink="blue" vlink="blue">
<basefont face="Verdana, Arial">
<center><h1>我的日程安排</h1><h3><%= strtitle %></h3>
<%
' 建立資料庫連接
end sub
function GetDataConnection()
dim oConn, strConn
Set oConn = Server.CreateObject("ADODB.Connection")
strConn = "Provider=SQLOLEDB; Data Source=adspm; Initial Catalog=TeamWeb; "
strConn = strConn & "User Id=TeamWeb; Password=x"
oConn.Open strConn
set GetDataConnection = oConn
end function
%>
create table Schedule (
idSchedule smallint identity primary key,
dtDate smalldatetime not null,
vcEvent varchar(100) not null
)
go
create procedure GetSchedule (@nMonth tinyint, @nYear smallint)
as
select idSchedule, convert(varchar, datepart(dd, dtDate)) 'nDay', vcEvent
from Schedule
where datepart(yy, dtDate) = @nYear and datepart(mm, dtDate) = @nMonth
order by datepart(dd, dtDate)
go
create procedure AddEvent (@vcDate varchar(20), @vcEvent varchar(100))
as insert Schedule select @vcDate, @vcEvent
go
create procedure DeleteEvent (@idSchedule smallint)
as delete Schedule where idSchedule = @idSchedule
go
註:更多精彩教程請關注三聯設計教程欄目。