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”返回的字符串?

解决方案 »

  1.   

    换成Select吧,或者使用输出参数。
      

  2.   

    raiseerror() 具体用法查下联机丛书
      

  3.   

    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
    这样就可以了