I am able to execute the below query
SELECT [Dbo].[fn_get_date](GETDATE(), 7, 1, 1, 1)
I am trying to call the function from C#.
If I pass hard string, I am getting the same data. But when I am trying to pass the date as parameter, It is throwing error. What am I doing wrong.?
public DateTime? get_settlement_date(DateTime startDate, int numberOfDays, string calendar)
{
using (var connection = new SqlConnection(_connection_string))
{
connection.Open();
var query = "SELECT [Dbo].[fn_get_date] (GETDATE(), 7, 1, 1, 1)"; // This is executing fine
query = $"SELECT [Dbo].[fn_get_date] ({startDate}, 1, 1, 1, 1)"; // This is throwing error
var objCommand = new SqlCommand(query, connection);
var settlement_Date = objCommand.ExecuteScalar();
return (DateTime) settlement_Date;
}
}
I don't want to create another stored procedure here.