我有一个插入存储过程,我想检查电子邮件是否已经存在,如果存在我必须向用户显示错误,但是如何抛出错误并在后面的代码中捕获它?
CREATE procedure [dbo].[SP_ProfileRegMaster]
@UserId Varchar(50),
@FirstName Varchar(50)
@EmailID varchar (50)
@result int out)
AS
BEGIN
IF EXISTS (SELECT EmailId FROM Profile_Master WHERE EmailId = @EmailId)
BEGIN
SET @result = 0
ELSE
RAISERROR ('Email address does not exist.', 1, 1)
END
C#代码:
result = cmd1.Parameters.Add("@result", System.Data.SqlDbType.Int);
result.Direction = System.Data.ParameterDirection.Output;