【问题标题】:LinqToSql query in Crystal Report returns SystemNotSupportedExceptionCrystal Report 中的 Linq To Sql 查询返回 System NotSupportedException
【发布时间】:2019-10-23 18:16:05
【问题描述】:

我用来构建 Crystal Report 的 TO-SQL` 查询:

 private void Arrivages()
    {
        using(DataClasses1DataContext dc=new DataClasses1DataContext())
        {
            var datas = (from art in dc.FICHES_ARTICLES
                         join ent in dc.ENTREES_STOCKS on art.ART_CODE equals ent.ART_CODE
                         where art.ART_SITE == 7 && art.ART_CODE == "A34815E1"
                         select new
                         {
                             art.ART_CODE,
                             art.ART_LIBELLE1,
                             art.ART_LIBELLE2,
                             //art.ART_EAN13,
                             art.ART_SIGNEQ,
                             ent.ENTSTK_LOT,
                             ent.ENTSTK_PNET,
                             ent.ENTSTK_DTENTREE,
                             ent.ENTSTK_NBU,
                             ent.ENTSTK_DATE_DEM,
                             ent.ENTSTK_USER
                         }).ToList();

            string reportPath = @"O:\GT\GT9999 - Applications\GL-T\Dossiers GL-T\Reports\Rapport1.rpt";
            ReportDocument cr = new ReportDocument();
            cr.Load(reportPath);
            cr.SetDataSource(datas);
            Cr_Viewer.ViewerCore.ReportSource = cr;
        }
    }

但是当我运行应用程序时出现错误:

SystemNot SupportedException : Dataset ne prend pas en charge System.Nullable.

英文留言

SystemNot SupportedException: DataSet 不支持 System.Nullable

我怎样才能摆脱这个错误?谢谢你帮助我。

【问题讨论】:

  • 调试单步执行时,datas是否为空?
  • 没有数据不为空,但一个字段可以有空值(ENTSTK_DATE_DEM)
  • 检查您的某个类是否正在使用不可为空的属性映射可空字段。例如数据库表:ENTREES_STOCKS - 字段:ENTSTK_DTENTREE 在数据库中为 NULL,但类为 DateTime,应为“DateTime?ENTSTK_DTENTREE”。

标签: c# wpf linq-to-sql


【解决方案1】:

既然您写了字段:ENTSTK_DATE_DEM 为空,请尝试替换空值。您也可以将其转换为字符串并执行以下操作:

var datas = (from art in dc.FICHES_ARTICLES
    join ent in dc.ENTREES_STOCKS on art.ART_CODE equals ent.ART_CODE
    where art.ART_SITE == 7 && art.ART_CODE == "A34815E1"
    select new { art, ent }).ToList()
    {
         art.ART_CODE,
         art.ART_LIBELLE1,
         art.ART_LIBELLE2,
         art.ART_SIGNEQ,
         ent.ENTSTK_LOT,
         ent.ENTSTK_PNET,
         ent.ENTSTK_DTENTREE,
         ent.ENTSTK_NBU,
         ENTSTK_DATE_DEM = ent.ENTSTK_DATE_DEM.HasValue ? ent.ENTSTK_DATE_DEM.Value.ToString() : string.Empty,
         ent.ENTSTK_USER
       };

不要忘记在报告中也将字段转换为字符串。

【讨论】:

  • 我写过:ENTSTK_DATE_DEM = ent.ENTSTK_DATE_DEM ??默认(日期时间)
  • 但是由于返回的日期不在要求的值之间,所以出现错误。
  • 顺便说一句,默认日期时间是1/1/0001 12:00:00 AM
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多