Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I just require the value of unique identifier from SQL Server Stored Procedure i.e, user id from username..... Is it possible to get or not

Can anyone suggest me for this.....

What I have tried:

My SQL Query:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[Usp_UserIDbyUserName] 
	@LoginName VARCHAR(15)
AS
BEGIN
	
	SELECT UsersID FROM Users WHERE UserName =@LoginName

END


and i am using dapper framework to retrieve the user id... The code as follows:
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyString"].ConnectionString))
            {
                var param = new DynamicParameters();
                param.Add("@LoginName", username);
                return con.Query<string>("Usp_UserIDbyUserName", param, null, true, 0, CommandType.StoredProcedure).SingleOrDefault();
            }
Posted
Updated 28-Aug-17 1:16am

1 solution

You are trying to return it as a string - if it's a GUID column, then you want something like
C#
return (con.Query<Guid>("Usp_UserIDbyUserName", param, null, true, 0, CommandType.StoredProcedure).SingleOrDefault()).ToString();
 
Share this answer
 
Comments
Member 8583441 28-Aug-17 7:29am    
Thank you very much.... but ToString() is not required i think because i deleted it and i got the data from the database....
Thank you very much once again @OriginalGriff
OriginalGriff 28-Aug-17 7:38am    
You're welcome!

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