C# code is
public void GetUserLoginName(string Username)
{
SqlConnection sqlcon;
SqlCommand sqlcmd;
try
{
sqlconnstring = ConfigurationManager.ConnectionStrings["CONERP"].ConnectionString;
sqlcon = new SqlConnection(sqlconnstring);
sqlcon.Open();
sqlcmd = new SqlCommand("GetUserLoginName", sqlcon);
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.Parameters.Add("@Username", SqlDbType.VarChar).Value = Username;
SqlParameter rolename = sqlcmd.Parameters.Add("@role", SqlDbType.VarChar);
rolename.Direction = ParameterDirection.Output;
Session["Loginusername"] = Convert.ToString(rolename.Value) ;
sqlcmd.Dispose();
sqlcon.Close();
}
catch (SqlException sqlerr)
{
}
}
and sql stored procedure is
USE [COERP]
GO
/****** Object: StoredProcedure [dbo].[GetUserLoginName] Script Date: 03/07/2014 13:34:01 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[GetUserLoginName](
@role varchar(max) out,
@Username varchar(max)
)
as
begin
set @role =(select Name from Newuser where Username=@Username)
end
the output of this code is '@role' not the value inside @role !!