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#中的异常
基础教程推荐
- C# 从 List<List<int>> 中删除重 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- WPF 模态进度窗口 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
