存储过程中注册错误 [英] error in store procedure written for registration

查看:60
本文介绍了存储过程中注册错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为存储注册编写了存储过程.
首先,它应该检查天气用户名是否已经存在(如果不存在),然后插入值并返回插入的记录的ID,否则返回-1.

即使插入记录,我也将i的值设为-1(i = cmd1.ExecuteNonQuery();)

I have written a store procedure for memregistration.
1st it should check weather the username already exist if it doesn''t then insert the values and return ID of the record inserted else return -1.

Even if the record is inserted I''m getting the value of i as -1 (i = cmd1.ExecuteNonQuery();)

   ALTER PROCEDURE [dbo].[sp_registration]
   @a varchar(50), @j varchar(50)
 , @b varchar(50), @k varchar(100)
 , @c varchar(50), @l varchar(300)
 , @d varchar(50), @m varchar(200)
 , @e varchar(50), @n varchar(50)
 , @f varchar(50), @o varchar(200)
 , @g varchar(50), @p varchar(50)
 , @h varchar(50), @q varchar(50)
 , @i varchar(50), @r varchar(50), @s varchar(50)
 , @result as bigint output

AS
BEGIN

 declare @count as int
 SET NOCOUNT ON;
 select @count = count(*) from table where a = a
 if(@count > 0)
 begin
  set @result = -1;
 end
 else
  begin
   insert into table(a,b,c....)
   values
   (a,b,c.......)
   set @result = @@identity
  end
 select @result
END

推荐答案

从表中选择@count = count(*),其中a = a

您是说a = @a吗?您是否考虑过不使用毫无意义且毫无意义的变量名?
select @count = count(*) from table where a = a

Did you mean a = @a ? Did you consider NOT using worthless and meaningless variable names ?


错误,同时发布是,我的意思是
a = @a
mistake while posting yes i mean
a = @a


只需将代码保持原样
仅替换"SET NOCOUNT ON;"
通过"SET NOCOUNT OFF;"
just keep your code as it is
only replace " SET NOCOUNT ON;"
by " SET NOCOUNT OFF;"


这篇关于存储过程中注册错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆