萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 網頁製作 >> 互動設計

經典 ASP 教程:從零構建 Web 日程安排表(含資料庫腳本)

早期 ASP 時代的經典教程,示範如何使用 VBScript 搭配 SQL Server 構建月視圖日程表,支援月份翻頁、事件增刪,並封裝資料庫連接實現配置集中管理。

核心架構

  • chunfeng.asp:主頁面,顯示月曆與事件,底部提供上/下月導航鏈接。
  • 全局函數:`GetDataConnection()` 封裝連接字串(Provider=SQLOLEDB, Data Source=adspm, Catalog=TeamWeb),修改配置只需改一處。
  • Calendar.sql:建表腳本(Schedule 表:idSchedule, dtDate, vcEvent)與三個存儲過程(`GetSchedule` 按月查詢、`AddEvent` 新增、`DeleteEvent` 刪除)。

關鍵代碼片段

<%@ 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
註:更多精彩教程請關注三聯設計教程欄目。
copyright © 萬盛學電腦網 all rights reserved