How can I call a SQL function in C#?

前端 未结 4 685
醉酒成梦
醉酒成梦 2021-01-05 12:36

I have created a function in SQL, now I need to use that function in my C# application.

I tried using something like this, but it seems I\'m doing it wrong since I\'

4条回答
  •  無奈伤痛
    2021-01-05 12:59

    At a glance, the first thing I can see is that you aren't specifying the object owner / schema; that is required for functions, so it should be select dbo.Function1(...

    Second: look at what your call to string.Format generates; that is generating @1 and @n for n another integer, but that is not a valid parameter name. Which is handy, because

    Third: you didn't add any parameters

    Fourth: for a table UDF (rather than a scalar UDF), you must select * from dbo.Function1(..., not just select dbo.Function1(...

提交回复
热议问题