小弟现在在写一个网站,全部的SQL语句用的是存储过程来执行的.每一人页面要进行的:增删改查功能全部写在了一个存储过程中,用参数@type来区分不同的操作.@state 返回操作的结果.
现在的问题是:在进行add新增操作时可以得到@state 的值,但是其它操作却得不到.
我觉得很奇怪,因为另一个页面我也是这样写的,没有问题.执行时很正常.还有一点是我在查询分析器里执行时可以得到输出参数的值,但是用代码却不行.代码应该没问题的,因为我都是用的同一个方法.
哪位高人能帮俺解答一下
/*
景点管理
*/
CREATE PROCEDURE SightMgr
(
@id nvarchar (40),--景点编号
@Name nvarchar (30),--景点名称
@area nvarchar (40),--景点所在地区
@img nvarchar (50),--景点图片
@type nvarchar (10),--操作类型
@txt text ,--景点描述
@state nvarchar (5) output--状态
)
as
if @type='add'
begin
if exists(select * from kindname where [Name]=@Name)
begin
set @state='true'--表示已经存在此景点不能新增加
end
else
begin
set @state='false'
insert into kindname(guid,type,[name],img,descript,area)values(@id,'C',@Name,@img,@txt,@area)
endend
if @type='update'
begin
if exists(select * from kindname where [Name]=@Name)
begin
set @state='true'--表示已经存在此景点不能更新
end
else
begin
set @state='false'
update kindname set [name]=@name,img=@img,descript=@txt,area=@area where guid=@id
end
end
if @type='delete'
begin
delete from kindname where type=N'C' and guid=@id
set @state=N'false'
end
if @type='read'
begin
if @id=''
begin
select * from kindname where type='C'
end
else
begin
select * from kindname where type='C'  and guid=@id
end
set @state='false'
end
GO