This is used to give a direction to output parameter. When we write a stored procedure and when we declare output parameter in it in which we have to store output. This output parameter we have to declare in code also. While adding this parameter in code we have to use ParameterDirection.Output.
Example : -
Stored Procedure : -
CREATE PROCEDURE [dbo].[USP_AuthenticateUsers]
@username nvarchar(255),
@password varbinary(MAX),
@userId int output,
AS
BEGIN
SET @userId=0
SELECT @userId=userId , @roleId=roleId FROM Users WHERE username=@username and [password]=@password
END
Code : -
Public Function AuthenticateUser(ByVal username As String, ByVal password As Byte(), ByVal userIPAddr As String) As structUserSession
Dim objCom As New System.Data.SqlClient.SqlCommand
objCom.CommandType = CommandType.StoredProcedure
objCom.CommandText = "USP_AuthenticateUsers"
objCom.Parameters.Add("userName", SqlDbType.NVarChar, 255).Value = username
objCom.Parameters.Add("password", SqlDbType.VarBinary, password.Length).Value = password
objCom.Parameters.Add("userId", SqlDbType.Int).Direction = ParameterDirection.Output
DB.ExecuteNonQuery(objCom)
Dim objStructUserSession As New structUserSession
objStructUserSession.userId = objCom.Parameters.Item("userId").Value
Return objStructUserSession
End Function
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment