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 so, as there a lot of examples on calling stored procs about)
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With