Reputation: 368
I have been trying to return string value after insert however my data is always truncated. It returns only the first character of the string.
My stored procedure:
ALTER PROC [dbo].[usp_add_user]
(@firstName nvarchar(50),
@lastName nvarchar(50),
@email nvarchar(100),
@password nvarchar(100),
@userID nvarchar(50) OUTPUT)
AS
BEGIN
SET @userID = newid()
INSERT INTO [User] ([UserID], [FirstName], [LastName], [Email], [Password])
VALUES (@userID, @firstName, @lastName, @email, @password)
SELECT @userID;
END
My C# how I am trying to catch the value
access.Parameter["@userID"].Value.ToString();
When I execute the stored procedure in SQL Server Management Studio, it shows everything correctly, my @userID
is correct. However when it comes back to my Visual Studio I only get first character
Thank you
Upvotes: 0
Views: 87
Reputation: 3424
You need to specify the size to get the entire string
cmd.Parameters.Add(new SqlParameter("@userID", SqlDbType.NVarChar, 50));
cmd.Parameters["@userID"].Direction = ParameterDirection.Output;
Upvotes: 1