本文介绍了如何从SQL存储过程返回两个输出值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想从sql存储过程同时获得两个Output值。我正在使用visual studio 2005和sql server 2005.在我存储的程序中,没有问题它返回两个值。 @EmpSid @RevisionNo 79 2 我尝试过: 我的代码在这里 MySID = objCmd.Parameters .AddWithValue(@ EmpSid,0) RevisionNo = objCmd.Parameters.AddWithValue(@ RevisionNo,1) objCmd.Parameters.Item(@ EmpSid)。Direction = ParameterDirection.Output objCmd.Parameters.Item(@ RevisionNo)。Direction = ParameterDirection.Output objCmd.ExecuteNonQuery() Sql程序 ELSE IF @ Mode ='EDIT' BEGIN 从tblEmployeeMaster中选择@RevisionNo = RevisionNo + 1 SID = @ EmpSid UPDATE tblEmployeeMaster set CompanySID = @ CompanySID,EmpCode = @ Empcode,HonorficsSID = @ H onorficsSID,EmpName = @EmpName, Dob = @ Dob,MaritalStatusSID = @ MaritalStatusSID,GenderSID = @ GenderSID,BloodGroup = @ BloodGroup, DateOfJoin = @ DateOfJoin,EmpPhoto = @ EmpPhoto,Notes = @Notes, RevisionNo = @ RevisionNo,CreatedBy = @ CreatedBy,CreatedOn = GETDATE(), EditedBy = @ CreatedBy,EditedOn = GETDATE()WHERE SID = @ SID SET @ EmpSid = @ SID END 显示错误 不能将值NULL插入列'RevisionNo',表'JSolutionHR.dbo.tblEmployeeMaster';列不允许空值。更新失败。 该语句已被终止。 解决方案 如评论中所述,@ RevisionNo为null。该错误与多个输出参数无关。错误应该很清楚。您正尝试将null放入不接受null的列。 选择。 .. 来自 tblEmployeeMaster 其中 SID = @EnSid 更新 tblEmployeeMaster ... WHERE SID = @SID SET @ EmpSid = @ SID 第一个 WHERE 子句应使用 @SID ,而不是 @EmpSid : SELECT @ RevisionNo = RevisionNo + 1 FROM tblEmployeeMaster WHERE SID = @ SID I want to get two Output values at the same time from the sql stored procedure .I am using visual studio 2005 and sql server 2005.In my stored proceudre there was no problem it returns Two Values.@EmpSid @RevisionNo 79 2 What I have tried:My code is hereMySID = objCmd.Parameters.AddWithValue("@EmpSid", 0) RevisionNo = objCmd.Parameters.AddWithValue("@RevisionNo", 1) objCmd.Parameters.Item("@EmpSid").Direction = ParameterDirection.Output objCmd.Parameters.Item("@RevisionNo").Direction = ParameterDirection.OutputobjCmd.ExecuteNonQuery()Sql ProcedureELSE IF @Mode='EDIT' BEGIN Select @RevisionNo = RevisionNo+1 from tblEmployeeMaster where SID=@EmpSid UPDATE tblEmployeeMaster set CompanySID=@CompanySID, EmpCode=@Empcode,HonorficsSID=@HonorficsSID,EmpName=@EmpName, Dob=@Dob, MaritalStatusSID=@MaritalStatusSID, GenderSID=@GenderSID, BloodGroup=@BloodGroup, DateOfJoin=@DateOfJoin,EmpPhoto=@EmpPhoto ,Notes=@Notes,RevisionNo=@RevisionNo, CreatedBy=@CreatedBy, CreatedOn=GETDATE(), EditedBy=@CreatedBy,EditedOn=GETDATE() WHERE SID=@SID SET @EmpSid=@SIDEND It shows an errorCannot insert the value NULL into column 'RevisionNo', table 'JSolutionHR.dbo.tblEmployeeMaster'; column does not allow nulls. UPDATE fails.The statement has been terminated. 解决方案 As mentioned in the comments, @RevisionNo is null. The error has nothing to do with multiple output parameters. The error should be pretty clear. You are trying to put null into a column that does not accept null.Select ... from tblEmployeeMaster where SID = @EmpSidUPDATE tblEmployeeMaster ... WHERE SID = @SIDSET @EmpSid = @SIDThat first WHERE clause should be using @SID, not @EmpSid:SELECT @RevisionNo = RevisionNo + 1 FROM tblEmployeeMaster WHERE SID = @SID 这篇关于如何从SQL存储过程返回两个输出值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-21 10:03