摘要:
教程:ASP+SQL Server制作留言板的完整小例子,写写关于SQL Server数据库的简单使用过程的教程,也算一个小总结!记录一些常用的方法,关键字,单词等,供以后查阅用!我们用ASP+SQL Server做个简单的留言板为例!关键字:
ASP SQL Server 留言板 正文:
操作(INSERT、 UPDATE、 DELETE),而仅是执行触发器本身
--或者说发生Delete事件时执行,该触发器AS后语名会替换过delete语句的执行
AS
Delete From subFeedback where Feedback_ID in(select Feedback_ID from deleted)
--删除表subFeedback外键与删除feedback主键相同的值
Delete From Feedback where Feedback_ID in(select Feedback_ID from deleted)
2、第二个触发器:当subFeedback有新增记录时,Feedback.subFeedback_count字段记数增加! Create Trigger Trigger_update_subFeedback
ON subFeedback
For insert
--注间和Instead OF的区别,For是当insert语句执行完后再执行解发器AS后的语句
AS
update Feedback set subFeedback_count=subFeedback_count+1 where Feedback_ID in(select Feedback_ID from inserted)
另外:如果考虑的较周全点,当subFeedback中的记录删除时,Feedback_subFeedback_count字段还要减1,触发器的写法和上面一相似,为减短教程,就不在增加!
四、建立两个存储过程用来保存增加的Feedback和subFeedback记录
Create Procedure proc_insert_Feedback --创建存储过程proc_insert_Feedback
@Title nvarChar(256),@Content text --定义参数变量
AS
Insert into Feedback (Title,Content) values(@Title,@Content) --执行语句
GO
Create Procedure proc_insert_subFeedback
@Feedback_ID int,@Content text
AS
Insert into subFeedback (Feedback_ID,Content) values(@Feedback_ID,@Content)
五、建立asp文件,完成留言板制作!
1、创建conn.asp文件,与数据库连接。 <%
dim conn
set conn=Server.createobject("ADODB.CONNECTION") '创建连接对象
conn.open="Provider=SQLOLEDB; Data Source=127.0.0.1;" & _
"Initial Catalog=Feedback; User ID=sa; password=sa;"
'打开连接。换成你的server-IP(如果也是本机不用修改),数据库用户名,密码!
%>
2、创建List.asp显示留言,内容。这里我把增加的 Form 也加到了文件底部,减少文件的个数。 <!--#include file="conn.asp"--><!--用include file包含数据库连接文件。-->
<%
SQL="select * from Feedback"
Set rs=Server.CreateObject("ADODB.Recordset") '创建数据集rs
rs.open SQL,conn,1,3 '打开
if not rs.eof then
output="" '定义字符串变量output,输出
do while not rs.eof '外循环开始
output=output&rs("title")
output=output&"--<a href=Feedback.asp?feedback_ID="&rs("feedback_ID")&"&title="&rs("title")&">回复该留言</a>["&cstr(rs("subFeedback_count"))&"]<hr>"
'建立回复留言的链接,并把要回复的留言的记录Feedback_ID和Title传给Feedback.asp
'Feedback用来标志是回复了哪条记录,增加数据库用!Title用来显示回
[1][2][3][4]