姬長信(Redy)

使用C#,如何执行tsql用户功能并获取其返回…


我有以下tsql函数:

ALTER FUNCTION [dbo].[fn_MyFunc] (
        @AccountId varchar(50)
)
returns bit
as 
begin 

    declare @IsEligible bit
        --some calculation
    return @IsEligible


end 

使用c#,这是调用此tsql函数并获取其返回值的方法吗?

     Database database = DatabaseFactory.CreateDatabase("DB");
     using (DbCommand dbCommand = database.GetStoredProcCommand("fn_MyFunc"))
                    {
                        database.AddInParameter(dbCommand, "@AccountId", DbType.String, "1234");
 bool returnedVAlue = (bool)dbCommand.ExecuteScalar();
}