Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 here
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 Procedure
ELSE 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=@SID
END  



It shows an error
Cannot insert the value NULL into column 'RevisionNo', table 'JSolutionHR.dbo.tblEmployeeMaster'; column does not allow nulls. UPDATE fails.
The statement has been terminated.
Posted
Updated 20-Sep-18 3:58am
v5
Comments
jaket-cp 19-Sep-18 5:41am    
Looking at the error message - put another way - it says attempting to insert null into
JSolutionHR.dbo.tblEmployeeMaster.RevisionNo

Check to see what you are getting for
Select @RevisionNo = RevisionNo+1 from tblEmployeeMaster where SID=@EmpSid

Assuming it is getting to this part of the query

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.
 
Share this answer
 
SQL
Select ... from tblEmployeeMaster where SID = @EmpSid
UPDATE tblEmployeeMaster ... WHERE SID = @SID
SET @EmpSid = @SID

That first WHERE clause should be using @SID, not @EmpSid:
SQL
SELECT @RevisionNo = RevisionNo + 1 FROM tblEmployeeMaster WHERE SID = @SID
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900