如何使用同一表中的name列从SQL Server 2012存储过程中获取唯一标识符的值 [英] How to get the value of unique identifier from SQL server 2012 stored procedure using name column in the same table

查看:124
本文介绍了如何使用同一表中的name列从SQL Server 2012存储过程中获取唯一标识符的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要SQL Server存储过程中唯一标识符的值,即来自用户名的用户ID .....是否可以获得



任何人都可以建议我.....



我尝试过的事情:



我的SQL查询:

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





我正在使用dapper框架来检索用户ID ...代码如下:



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();
            }

推荐答案

您试图将其作为字符串返回 - 如果它是GUID列,那么您需要类似的东西

You are trying to return it as a string - if it's a GUID column, then you want something like
return (con.Query<Guid>("Usp_UserIDbyUserName", param, null, true, 0, CommandType.StoredProcedure).SingleOrDefault()).ToString();


这篇关于如何使用同一表中的name列从SQL Server 2012存储过程中获取唯一标识符的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆