Sql server 如何从ado.net调用TSQL函数
我在SQL Server中定义了一个函数(接受一个字符串和一个int),如何使用ADO.NET调用它Sql server 如何从ado.net调用TSQL函数,sql-server,ado.net,Sql Server,Ado.net,我在SQL Server中定义了一个函数(接受一个字符串和一个int),如何使用ADO.NET调用它 (如果它与调用存储过程100%相同,请这样说,因为有很多关于调用存储过程的示例)唯一的区别是必须为返回值添加一个特殊参数 见: @SašaĆetković引用的链接是MySqlCommand,因为它是预先存在的答案,答案中的代码片段是SQL Server using (var connection = new SqlConnection("ConnectionString")) usin
(如果它与调用存储过程100%相同,请这样说,因为有很多关于调用存储过程的示例)唯一的区别是必须为返回值添加一个特殊参数 见:
@SašaĆetković引用的链接是MySqlCommand,因为它是预先存在的答案,答案中的代码片段是SQL Server
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;
}