【发布时间】:2014-06-07 15:16:52
【问题描述】:
我试图使用导出到 Excell、PDF、TextFile 来生成报告。好吧,我在 MVC 中这样做。我有一个名为 SPBatch 的类(这是我的 SQL 中存储过程的确切名称),它包含以下内容:
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 中导出时,我总是在这部分代码中遇到问题“DataSet 不支持 System.Nullable” :
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。
我该怎么办?
【问题讨论】:
-
我建议不要使用
DataSet,因为它似乎不支持您的要求。
标签: c# asp.net-mvc-4 dataset export-to-excel nullable