postgresql 无法写入处理程序类型为DateHandler的CLR类型System.String

uajslkp6  于 2022-12-18  发布在  PostgreSQL
关注(0)|答案(1)|浏览(282)

我正在使用postgresql处理npg
我面临以下错误
https://imgur.com/p26YFIj
函数

-- select public.getmonthfromdatetestO('2022-01-02')
CREATE OR REPLACE FUNCTION public.getmonthfromdatetestO(
    orderdate date)
    --albumid integer)
    RETURNS SETOF record 
    LANGUAGE 'sql'
    COST 100
    VOLATILE PARALLEL UNSAFE
    ROWS 1000

AS $BODY$
SELECT count(albumid) ,extract(month FROM orderdate) AS yr_month
    FROM public.orderalbum
    WHERE
        extract(year FROM orderdate) = 2022
        GROUP BY albumid,orderdate  
        --GROUP BY albumid,orderdate
--select extract(month from orderdate)::int;
$BODY$;

功能的o/p

(13,12)
(13,12)
(13,12)
(13,12)
(13,12)
(13,12)
(6,12)
(6,12)
(13,12)
(14,12)
(14,12)

家庭控制器

[HttpGet]
        public ActionResult getmonthSales()
        {      
            string sql3 = @"getmonthfromdatetestO";
 
            conn.Open();
            NpgsqlCommand pgcom = new NpgsqlCommand(sql3, conn);
            pgcom.CommandType = CommandType.StoredProcedure;
            
            pgcom.Parameters.AddWithValue("orderdates", NpgsqlTypes.NpgsqlDbType.Date, "2022-01-01");
            
            NpgsqlDataReader pgreader = pgcom.ExecuteReader();

            while (pgreader.Read())
            {
                int albumid = pgreader.GetInt32(1);
                int surname = pgreader.GetInt32(2);
            }


堆栈跟踪:

at lambda_method(Closure , NpgsqlTypeHandler , Object , NpgsqlLengthCache& , NpgsqlParameter )
   at Npgsql.TypeHandling.NpgsqlSimpleTypeHandler`1.ValidateObjectAndGetLength(Object value, NpgsqlLengthCache& lengthCache, NpgsqlParameter parameter)
   at Npgsql.NpgsqlParameter.ValidateAndGetLength()
   at Npgsql.NpgsqlCommand.ValidateParameters()
   at Npgsql.NpgsqlCommand.<ExecuteDbDataReader>d__100.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at Npgsql.NpgsqlCommand.ExecuteReader()
   at MvcPractical.Controllers.HomeController.getmonthSales() in C:\Users\patilr\Documents\Visual Studio 2015\Projects\MvcPractical\MvcPractical\Controllers\HomeController.cs:line 233
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()

我一直在尝试,但没有工作,我一直在改变函数,也是c#,但不同的错误,我得到
我在谷歌搜索错误和函数和C#方面的变化,但我的问题没有解决,这就是为什么我在这里写我的问题
需要帮助

e4yzc0pl

e4yzc0pl1#

不能将字符串写为日期-从字符串(DateOnly.Parse("2022-01-01"))创建一个DateOnly示例,并将其作为参数值传递。

相关问题