|
发表于 2007 年 5 月 9 日 10:02:13
|
显示全部楼层
3. 更新记录
3.1 在查询分析器中构造 更新记录用的存储过程, 并更新 ID为1 的记录集
linenum
--使用数据库 shawl
use shawl
go
--构造更新用的存储过程, 名 dbo.t_updateSproc
create proc dbo.t_updateSproc
--定义变量 id, title, content
@id int,
@title varchar(255),
@content varchar(4000)
as
begin
--设置不返回受影响行的结果
set noCount on
--更新内容, 如果变量 id 为空, 则不更新内容
update t set title=@title, content=@content where id=coalesce(@id,0)
--选取并显示被更新的记录集
select * from t where id=@id
end
go
--授权给用户(组)
grant exec on dbo.t_updateSproc to dbo
go
--在查询分析器中执行存储过程, 更新列名 为ID 值=1 的行
exec dbo.t_updateSproc @id=1, @title='update title', @content='update content'
3.2 在 ASP 中使用存储过程执行更新操作
(请检查你有没有创建并引用 2.2.1 的 createCnn 与 closeCnn 函数)
linenum
<%
dim id, title, content
dim sql, rs, cnn
id=1
title="update title where id=1"
content="update content"
sql="exec dbo.t_updateSproc @title='"&title&"',@content='"&content&"',@id="&id
call createCnn(cnn)
cnn.open conn
set rs=cnn.execute(sql)
response.write "ID为: "&rs("id")&" 的记录集已更新"
rs.close
set rs=nothing
call closeCnn(cnn)
%> |
|