企业库中的SQL自定义函数

Gus*_*bio 0 .net c# sql-server enterprise-library

有没有办法用Enterpise Library执行SQL自定义函数?我已经尝试过Database.ExecuteScalar()但由于某种原因它返回null.

这是我的功能:

Database db = DatabaseFactory.CreateDatabase("ConnectionString");
DbCommand cmd = db.GetStoredProcCommand("FunctionName");
db.AddInParameter(cmd, "Value1", DbType.String, Param1Value);
db.AddInParameter(cmd, "Value2", DbType.String, Param2Value);
return Convert.ToBoolean(db.ExecuteScalar(cmd)); 
Run Code Online (Sandbox Code Playgroud)

这里db.ExecuteScalar(cmd)方法返回null.存储过程不会发生这种情况.

顺便说一下,即时通讯使用4.0版

谢谢.

cst*_*ick 5

您必须创建一个select语句,从函数中选择结果并执行该语句.

"SELECT*FROM FunctionName(@ Value1,@ Value2)"

或者你可以在一个过程中包装你的函数调用并调用该过程,我更喜欢这个.