public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArg
Try this :
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, newPartSalePrice = s.SPartSalePrice == null ? 0 : s.SPartSalePrice }).ToArray();
CrystalReport1 c = new CrystalReport1();
c.SetDataSource(d);
crystalReportViewer1.ReportSource = c;
}
}
you should check for null in the selection with
s.SPartSalePrice == null ? 0 : s.SPartSalePrice
whetherit is null or not if it is null then it will return 0 otherwise it returns the value and assign it to the new variable
newPartSalePrice = s.SPartSalePrice == null ? 0 : s.SPartSalePrice