如何在C#代码中使用@Result变量 [英] How Can I Use @Result Variable In C# Code

查看:338
本文介绍了如何在C#代码中使用@Result变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  SET   ANSI_NULLS   ON  
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo]。[SP_User_Entry]

@name varchar 100 ),
@desg_code char 3 ),

@ telephone_off varchar 15 ) ,
@ mobile varchar 15 ),
@ phone_res varchar 20 ),
@ address_res varchar 100 ),
@ state_code char 2 ),
@ address_off varchar 300 ),
@ district_code char 3 ),
@ cat_code char 3 ),
@ telephoneres_code varchar 6 ),
@ telephoneof f_code varchar 6 ),

@ machine_ip varchar 30



AS
DECLARE @ result int
DECLARE @ reg_no char 10
DECLARE @ today char 6
DECLARE @ SRNO int
DECLARE @ Temp varchar 50
DECLARE @ jeeroes char 7
DECLARE @ inserr1 as int

set @ today = replace(< span class =code-keyword> convert ( varchar ,getdate(), 3 ),' /'' < span class =code-string>')

begin transaction OT

选择 @ reg_no = max(reg_no)来自 user_info 其中 substring(reg_no, 1 6 ) = @ today
如果 @ reg_no null
SET @ SRNO = 1
else
begin
SET @SRNO = CAST(SUBSTRING( @ reg_no 7 10 as 整数)
SET @ SRNO = @ SRNO + 1
end
set @ jeeroes = substring( ' 0000' 1 ,4-len( @SRNO ))
SET @ TEMP = @ today + rtrim( @ jeeroes )+ CAST( @ SRNO as varchar (< span class =code-digit> 4 ))
SET @ reg_no = @ TEMP

if select count(*)来自 user_info < span class =code-keyword>其中 mobile = @ mobile)< 1
begin
insert into user_info(reg_no,name,desg_code,phone_res,telephone_off,mobile,address_res,state_code,address_off,district_code,cat_code,telephoneoff_code,telephoneres_code,machine_ip,entry_date, IsActive)
@ reg_no @ name @ desg_code @ phone_res @telephone_off @ mobile @ address_res @state_code @ address_off @ district_code @cat_code @ telephoneoff_code @ telephoneres_code @ machine_ip ,GETDATE(),' false'
选择 @ inserr1 = @@ ERROR

end

if @ inserr1 = 0
开始
提交 交易 OT
return 0
end
其他
开始
rollback transaction OT
return 1
end

解决方案

首先:到目前为止你尝试了什么?



第二:你需要处理代码。这是不可读的。



第三:看看这些链接。应该有助于找到一种方法:



http ://msdn.microsoft.com/en-us/library/d7125bke.aspx [ ^ ]



http://msdn.microsoft.com/en-us/library/d7125bke.aspx [ ^ ]



http://social.msdn.microsoft.com/Forums/en-US/ea33abdf-6863-4e11-887e-ebbcf4cc1e5f/how-to-get-sql-server-stored-procedures-return -value-and-output-value-with-c?forum = csharpgeneral [ ^

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[SP_User_Entry]

 @name varchar(100),
 @desg_code char(3),  

 @telephone_off varchar(15),  
 @mobile varchar(15), 
  @phone_res varchar (20),
 @address_res varchar(100),
 @state_code char(2),
 @address_off varchar(300),
 @district_code char(3),
 @cat_code char(3),
 @telephoneres_code varchar(6),
 @telephoneoff_code varchar(6),

 @machine_ip varchar(30)
 

   
AS  
DECLARE @result int
DECLARE  @reg_no char(10)
DECLARE @today char(6)
DECLARE @SRNO int    
DECLARE @Temp varchar(50)    
DECLARE @jeeroes char(7)  
DECLARE @inserr1 as int

set @today = replace(convert(varchar, getdate(), 3),'/','')

begin transaction OT 

	select @reg_no=max(reg_no) from user_info where substring(reg_no,1,6)=@today
	if @reg_no is null
		SET @SRNO=1
	else
		begin
         SET @SRNO=CAST(SUBSTRING(@reg_no,7,10) as integer)
         SET @SRNO=@SRNO+1
		end
    set @jeeroes=substring('0000',1,4-len(@SRNO))
    SET @TEMP= @today+rtrim(@jeeroes)+CAST(@SRNO as varchar(4))
    SET @reg_no=@TEMP 

   if (select count(*) from user_info where mobile=@mobile)< 1
   begin
	insert into user_info (reg_no,name,desg_code,phone_res,telephone_off,mobile,address_res,state_code,address_off,district_code,cat_code, telephoneoff_code,telephoneres_code,machine_ip,entry_date,IsActive)
	values(@reg_no,@name,@desg_code,@phone_res,@telephone_off,@mobile,@address_res,@state_code,@address_off,@district_code,@cat_code,@telephoneoff_code,@telephoneres_code,@machine_ip,GETDATE(),'false')
	select @inserr1=@@ERROR 

	end

if @inserr1=0
	   begin
		  commit transaction OT
		  return 0
	   end
	   else
	   begin          
		 rollback transaction OT          
		 return 1
	   end

解决方案

First: What have you tried so far?

Second: You need to work on code. It's unreadable.

Third: Look at these links. Should help to find a way:

http://msdn.microsoft.com/en-us/library/d7125bke.aspx[^]

http://msdn.microsoft.com/en-us/library/d7125bke.aspx[^]

http://social.msdn.microsoft.com/Forums/en-US/ea33abdf-6863-4e11-887e-ebbcf4cc1e5f/how-to-get-sql-server-stored-procedures-return-value-and-output-value-with-c?forum=csharpgeneral[^]


这篇关于如何在C#代码中使用@Result变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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