Stored procedure return value
Hello all,
I am trying to understand C# in VS 2005 sepcifically ASP web pages, I have managed to write some simple stored procedures to our SQL 200 server, that populate datatables fine.
But when it comes to writing a stored procedure to return a value, well boy is this giving me a headache!!!!
History:-
Stored procedure
ALTER PROCEDURE dbo.CountCalls
(
@HowManyCallsToday int output
)
AS
SELECT @HowManyCallsToday = Count(*)
FROM HD_Call
WHERE (CONVERT(Varchar(10), DateRaised, 101) = CONVERT(varchar(10), GETDATE(), 101))
AND Status In ('Assigned', 'In Progress', 'Logged', 'On Hold', 'ReadyToGoLive');
RETURN
When I try to get the value of @HowManyCallsToday back into the C# code I am gettin alsorts of wierd and wonderful things happening.
C # code:
This is a class being called form the ASP page in Page_load.
Calling code:
int howManyCalls;
// How many logged errors?
howManyCalls = CatalogAccess.GetDailyCallCount(out howManyCalls);
Called class:
public static string GetDailyCallCount(out int howManyCalls)
{
DbCommand comm = GenericDataAccess.CreateCommand();
comm.CommandText = "CountCalls";
DbParameter param = comm.CreateParameter();
param.ParameterName = "@HowManyCallsToday";
param.Direction = ParameterDirection.InputOutput;
param.DbType = DbType.Int16;
comm.Parameters.Add(param);
//DataTable table = GenericDataAccess.ExecuteSelectCommand(comm);
comm.Parameters["@HowManyCallsToday"].Direction = ParameterDirection.Output;
int HowManyCallsToday;
GenericDataAccess.ExecuteSelectCommand(comm);
HowManyCallsToday = Int32.Parse(comm.Parameters["@HowManyCallsToday"].Value.ToString());
return HowManyCallsToday; // Error cannot implicitly convert int to string
}
Any help offered will be grately appreciated.