I have a function defined in SQL Server (that takes a string and a int) how do I call it with ADO.NET?
(If it is 100% same as calling a stored proc, please just say
The only difference is that you must have a special paramter added for the return value
See: MySqlCommand call function
using (var connection = new SqlConnection("ConnectionString"))
using (var command = connection.CreateCommand())
{
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "MyFunction";
SqlParameter returnValue = command.Parameters.Add("@RETURN_VALUE", SqlDbType.Int);
returnValue.Direction = ParameterDirection.ReturnValue;
connection.Open();
command.ExecuteNonQuery();
return returnValue.Value;
}