数据集不支持System.Nullable.在出口 [英] DataSet does not support System.Nullable<> in Export

查看:80
本文介绍了数据集不支持System.Nullable.在出口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用导出到Excell,PDF,TextFile"生成报告.好吧,我正在MVC中执行此操作.我有一个名为SPBatch的类(这是我的SQL中存储过程的确切名称),它包含以下内容:

I was trying to generate a Report using Export to Excell, PDF, TextFile. Well I am doing this in MVC. I have a class which I named SPBatch (which is the exact name of my Stored Procedure in my SQL) and it contains the following:

public string BatchNo { get; set; }
public string ProviderName { get; set; }
public Nullable<System.Int32> NoOfClaims { get; set; }
public Nullable<System.Int32> TotalNoOfClaims { get; set; }
public Nullable<System.Decimal> TotalBilled { get; set; }
public Nullable<System.Decimal> TotalInputtedBill { get; set; }
public Nullable<System.DateTime> DateCreated { get; set; }
public Nullable<System.DateTime> DateSubmitted { get; set; }
public Nullable<System.DateTime> DueDate { get; set; }
public string Status { get; set; }
public string RefNo { get; set; }
public string BatchStatus { get; set; }
public string ClaimType { get; set; }

如您所见,我的某些列被声明为Nullable.从搜索并将结果显示在表格中后,一切顺利.我下面有几个按钮,这些按钮是用于导出的图像按钮,每次尝试在Excel中导出时,在此部分代码中总是出现"数据集不支持System.Nullable<> "的问题. :

as you can see some of my Columns are declared as Nullable. It went smoothly from searching and displaying the results in a table. I have several buttons below which are image buttons for export and every time I try to export in Excel, I always get the problem "DataSet does not support System.Nullable<>" in this part of my code:

foreach (MemberInfo mi in miArray)
{
    if (mi.MemberType == MemberTypes.Property)
    {
        PropertyInfo pi = mi as PropertyInfo;
        dt.Columns.Add(pi.Name, pi.PropertyType); //where the error pop's up.

    }
    else if (mi.MemberType == MemberTypes.Field)
    {
        FieldInfo fi = mi as FieldInfo;
        dt.Columns.Add(fi.Name, fi.FieldType);
    }
}

该错误显示在带有注释的地方.你能帮我做什么?我尝试在代码中添加DBNull,但仍然收到相同的错误.我尝试在SPBatch中删除Nullable,但收到一个错误,需要将某些表声明为Nullable.

the error shows up on the one with a comment. Can you help me what to do? I tried adding DBNull in my code but still I get the same error. I tried removing Nullable in my SPBatch but I get an error that some tables are need to be declared as Nullable.

我该怎么办?

推荐答案

尝试使用

dt.Columns.Add(pi.Name, Nullable.GetUnderlyingType(
            pi.PropertyType) ?? pi.PropertyType);

这篇关于数据集不支持System.Nullable.在出口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆