DataSet does not support System.Nullablelt;gt; exception in c#(DataSet 不支持 System.Nullablelt;gt;c#中的异常)
问题描述
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
RST_DBDataContext db = new RST_DBDataContext();
var d = (from s in db.TblSpareParts
select new { s.SPartName, s.SPartCode, s.ModelID, s.SPartLocation, s.SPartActive, s.SPartSalePrice }).ToArray();
CrystalReport1 c = new CrystalReport1();
c.SetDataSource(d);
crystalReportViewer1.ReportSource = c;
}
}
我正在尝试生成水晶报告由于在 c.SetDataSource(d) 处,sql 表中的 SPartSalePrice 可以为空;异常来了请解决
i am trying generate crystal report there in sql table SPartSalePrice is nullable due to that at c.SetDataSource(d); exception come please solve it
推荐答案
使用 匿名投影中的 null 合并 或 条件 运算符映射出null
:
Use the null coalescing or conditional operators in your anonymous projection to map out the null
:
合并:
var d = (from s in db.TblSpareParts
select new
{
s.SPartName,
...,
SPartSalePrice = s.SPartSalePrice ?? 0.0,
...
}).ToArray();
有条件的(对空值不是很有用,但对投影其他值很有用)
Conditional (Not really useful for nulls, but useful for projecting other values)
SPartSalePrice = s.SPartSalePrice == null ? 0.0 : s.SPartSalePrice,
该字段需要命名(我保留了原来的名称,SPartSalePrice
),以及替换的type
(0.0
) 应该匹配字段的类型.
The field needs to be given a name (I've kept the original one, SPartSalePrice
), and the type
of substitution (0.0
) should match the type of the field.
这篇关于DataSet 不支持 System.Nullable<>c#中的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:DataSet 不支持 System.Nullable<>c#中的异常


基础教程推荐
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01