|
学了几天的Stored Procedure的文章和资料,感觉用存储过程做ASP开发真的不错,下面是一个很简单的INSERT操作的例子! 1:首先在SQL EnterPrise 管理器里创建一个名为"softwareInfo1"的存储过程·下面是代码: CREATE PROCEDURE [dbo].[softwareInfo1] @target varchar(50), @title varchar(100), @comefrom varchar(50), @content varchar(3000), @addtime datetime, @clicktotal Int=1 AS insert softwareInfo(target,title,content,addtime,clickcount,comefrom) values(@target,@title,@content,@addtime,@clicktotal,@comefrom) GO 2:做ASP页面的代码: <!--#include file="/conn.asp"-->'定义了数据源文件和函数文件 <% 'Deal(X)是转换HTML 标签的函数 softinfotarget=Deal(request.form("softinfotarget"))'类型 softinfotitle=Deal(request.form("softinfotitle"))'标题 softinfocomefrom=Deal(request.form("softinfocomefrom"))'出处 softinfocontent=Deal(request.form("softinfocontent"))'内容 addtime=FormatDateTime(now(),vbshortdatetime)'添加时间 dotecount=1 SQLSTRTEMP="select title from softwareInfo where title='"&softinfotitle&"'" set TEMP=conn.Execute(SQLSTRTEMP) if NOT TEMP.eof Then Response.write "这条软件信息已经被添加了,请添加下一条信息!" response.end() Else '使用非存储过程SQLSTR="insert softwareInfo(target,title,content,addtime,clickcount,comefrom) values('"&softinfotarget&"','"&softinfotitle&"','"&softinfocontent&"','"&addtime&"','"&dotecount&"','"&softinfocomefrom&"')" '执行conn.Execute(SQLSTR) '下面是调用存储过程的代码
Set cmd=Server.CreateObject("adodb.command") Set cmd.activeConnection=conn cmd.commandText="softwareInfo1" cmd.commandType=4 Set test=cmd.Parameters test.append cmd.createParameter("target",200,1,50) test.append cmd.createParameter("title",200,1,100) test.append cmd.createParameter("comefrom",200,1,50) test.append cmd.createParameter("content",200,1,3000) test.append cmd.createParameter("addtime",7,1,50) test.append cmd.createParameter("clicktotal",3,1,50) cmd("target")=softinfotarget cmd("title")=softinfotitle cmd("comefrom")=softinfocomefrom cmd("content")=softinfocontent cmd("addtime")=addtime cmd("clicktotal")=dotecount cmd.Execute()
Response.write "成功添加" TEMP.close Set TEMP=Nothing End If %>

OVER
|