I have this Stored procedure that returns UserID:
ALTER PROCEDURE dbo.GetUserID
(
@TopicID int,
@AskerID int
)
AS
SELECT @AskerID = Post.Pt_CreatedBy
WHERE (Topic.Tp_ID = @TopicID)
RETURN @AskerID
Now when I call it from the Data access layer page using C#, I use this function:
MyDatabaseDataContext StudyAppdb = new MyDatabaseDataContext();
public int GetUserID(int TopicID)
{
int UserID = -1;
UserID = db.GetUserID(TopicID, UserID);
return UserID;
}
But GetUserID is supposed to take (int , ref int).... I don't know what is ref int & how can I pass it to the function.
Since GetUserID is supposed to take (int , ref int), you should also use the ref keyword explicily when calling this method. Instead of calling the method with db.GetUserID(TopicID, UserID) you should use the ref key word, something like:
public int GetUserID(int TopicID)
{
int UserID = -1;
UserID = db.GetUserID(TopicID, ref UserID);
return UserID;
}
You can read more about ref keyword.
You can Write a Function Instead of Stored Procedure like given below
CREATE FUNCTION dbo.GetUserID
(
@TopicID int,
@AskerID int
)
RETURNS INT
AS
BEGIN
SELECT @AskerID = Post.Pt_CreatedBy
WHERE (Topic.Tp_ID = @TopicID)
RETURN @AskerID
END
OR change the procedure with OUTPUT parameter. Then You have to change the data access layer code to capture that value..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With