I’ve recently changed a couple of functions recently while debugging a cte query (have gotten help here). I just changed a couple of functions.. this got my query to work.. but now when my C# client code calls those functions through stored procs for my program logic, I get the error “Procedure or function ‘DateTimeOfNextAvailableDataRun’ expects parameter ‘@NextDateTime’, which was not supplied.
” Maybe multiple values are coming back?
Here’s the function in its current form:
ALTER FUNCTION dbo.NextAvailableDataDownloadDateTime()
RETURNS date
BEGIN
RETURN (SELECT DATEADD(hour, 18, MIN(TradingDate)) AS TrDate
FROM tblTradingDays
WHERE (DATEADD(hour, 18, TradingDate) > dbo.LatestDataDownloadDate()))
END
And the stored proc that invokes it:
ALTER PROC DateTimeOfNextAvailableDataRun
@NextDateTime DateTime2 OUTPUT
AS
SELECT @NextDateTime = dbo.NextAvailableDataDownloadDateTime()
And lastly my client code, which did run before the change:
public DateTime DateTimeOfNxtAvailableDataRun()
{
DateTime dateTimeOfNxtAvailableDataRun;
using (SqlCommand cmd = new SqlCommand("DateTimeOfNextAvailableDataRun", this.sqlConnection))
{
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.ExecuteNonQuery();
dateTimeOfNxtAvailableDataRun = (DateTime)cmd.ExecuteScalar();
}
return dateTimeOfNxtAvailableDataRun;
}
Any takers? Again, the functions work within my sql server query (see recent posts by me) but now the calling code disagrees..
You should modify the body of the
usingstatement and add an output parameter before executing the command.