日期:2014-05-19  浏览次数:21172 次

存储过程之print语句
create   proc   proc_AddUsers
(
@Users_Name   varchar(20),
@Password   varchar(16),
@Description   varchar(50),
@Users_Role   int
)
as
        if   not   exists(select   Users_Name   from   Users   where   Users_Name=@Users_Name)
begin
insert   into   Users   values   (@Users_Name,@Password,@Description,@Users_Role)
end
        else
                print   'UserName   have   existed '
go
============================================================
如上一个存储过程,如何用C#来接收“print”返回的字符串?

------解决方案--------------------
换成Select吧,或者使用输出参数。
------解决方案--------------------
raiseerror() 具体用法查下联机丛书
------解决方案--------------------
create proc proc_AddUsers
(
@Users_Name varchar(20),
@Password varchar(16),
@Description varchar(50),
@Users_Role int,
@backinfo varchar(20) output
)
as
if not exists(select Users_Name from Users where Users_Name=@Users_Name)
begin
insert into Users values (@Users_Name,@Password,@Description,@Users_Role)
end
else
set @backinfo= 'UserName have existed '
go
这样就可以了