jamesdean666
asked on
C# and Return Stored Procedure result
I have the following Stored Procedure in SQL Server 2005:
IF OBJECT_ID('[dbo].[spBct_Ph nxMrtgee_U serProfile ]') IS NOT NULL
DROP PROCEDURE [dbo].[spBct_PhnxMrtgee_Us erProfile]
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[spBct_PhnxMrtgee_Us erProfile]
(
@UserId VARCHAR(20)
)
AS
IF @UserId = 'JDIBIASE' OR @UserId = 'HENKV' OR @UserId = 'CHARMENE' OR @UserId = 'JEFF'
BEGIN
SELECT @UserId = 'Y'
END
ELSE
SELECT @UserId = 'N'
SELECT @UserId AS RESULT
RETURN RESULT
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
I have the following code in my Data Layer in a C# VS 2008 Project, and I am trying to return the result of the above Stored Procedure:
public String UserProfile(string userId)
{
String result;
System.Data.Common.DbComma nd cmd = this.mConn.CreateCommand() ;
try
{
cmd.CommandTimeout = this.mCmdTimeout;
cmd.CommandType = CommandType.StoredProcedur e;
cmd.CommandText = "spBct_PhnxMrtgee_UserProf ile";
DbParameter p = cmd.CreateParameter();
p.ParameterName = "@UserId";
p.DbType = DbType.String;
p.Value = userId;
cmd.Parameters.Add(p);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();
THIS IS WHAT I AM TRYING TO FIGURE OUT:
result = Convert.ToString(cmd.Param eters["@Us erId"].Val ue);
}
catch (Exception ex)
{
log.ErrorException(System. Reflection .MethodBas e.GetCurre ntMethod() .Name, ex);
throw;
}
finally
{
cmd.Connection.Close();
}
return result;
}
How can I update my C# code to return the result of my stored procedure?
Thanks,
JD
IF OBJECT_ID('[dbo].[spBct_Ph
DROP PROCEDURE [dbo].[spBct_PhnxMrtgee_Us
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[spBct_PhnxMrtgee_Us
(
@UserId VARCHAR(20)
)
AS
IF @UserId = 'JDIBIASE' OR @UserId = 'HENKV' OR @UserId = 'CHARMENE' OR @UserId = 'JEFF'
BEGIN
SELECT @UserId = 'Y'
END
ELSE
SELECT @UserId = 'N'
SELECT @UserId AS RESULT
RETURN RESULT
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
I have the following code in my Data Layer in a C# VS 2008 Project, and I am trying to return the result of the above Stored Procedure:
public String UserProfile(string userId)
{
String result;
System.Data.Common.DbComma
try
{
cmd.CommandTimeout = this.mCmdTimeout;
cmd.CommandType = CommandType.StoredProcedur
cmd.CommandText = "spBct_PhnxMrtgee_UserProf
DbParameter p = cmd.CreateParameter();
p.ParameterName = "@UserId";
p.DbType = DbType.String;
p.Value = userId;
cmd.Parameters.Add(p);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();
THIS IS WHAT I AM TRYING TO FIGURE OUT:
result = Convert.ToString(cmd.Param
}
catch (Exception ex)
{
log.ErrorException(System.
throw;
}
finally
{
cmd.Connection.Close();
}
return result;
}
How can I update my C# code to return the result of my stored procedure?
Thanks,
JD
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER