I'm going to call data from the DAL, send it to the BLL, and I'll give it to XtraReport. The scenario is as follows: In the DAL:
public static List<t_Products> GetAllProductList()
{
try
{
return objContext.t_Products.OrderBy(c => c.f_ProName).ToList();
}
......
}
in the BLL:
public static List<t_Products> GetAllProductList()
{
return DAL.DALProducts.GetAllProductList();
}
in the UI:
List<t_Products> ProductList = BLLProducts.GetAllProductList();
var queryProduct=ProductList.Where(c => c.f_ProTypeID == 1)
.Select(current=>new {current.f_ProductID,current.f_ProCode,current.f_P roName,current.f_ProWeight,current.f_ProTypeID});
//create datatable from linq query
productDataTable =Utilities.IEnumerableToDataTable.LINQToDataTable( queryProduct);
private void simpleButton1_Click(object sender, EventArgs e)
{
if (productDT.Rows.Count > 0)
{
//sending datatable to Xtrareport
Reports.XtraReports.ProductsAndBOM x = new Reports.XtraReports.ProductsAndBOM(productDT);
x.Report();
}
else
.... }
Finally, I put in a XtraReport named ProductAndBOM, I have a DataSet called mahshamDataSet, in which there is a data table called t_Product. I've put the fields in this table on the report.I put the DataTable sent to the report, using the Merge command in the t_Product data table:
public partial class ProductsAndBOM : DevExpress.XtraReports.UI.XtraReport
{
public ProductsAndBOM()
{
InitializeComponent();
}
System.Data.DataTable requiredRawMaterilSource;
System.Data.DataTable productsSource;
public ProductsAndBOM(System.Data.DataTable products)
{
productsSource = products;
}
new public void Report()
{
mahshamDataSet1.t_Products.Merge(productsSource);
ProductsAndBOM productBOMXtraReport = new ProductsAndBOM();
ReportPrintTool printTool = new ReportPrintTool(productBOMXtraReport);
UserLookAndFeel lookAndFeel = new UserLookAndFeel(this);
lookAndFeel.UseDefaultLookAndFeel = false;
lookAndFeel.SkinName = "Office 2016 Colorful";
printTool.ShowRibbonPreview(lookAndFeel);
}
}
Unfortunately, when I merge the data table sent into the report with the mahshamDataSet1.t_Products table, I get the following error: An unhandled exception of type 'System.NullReferenceException' occurred in Mahsham.UI.exe Additional information: Object reference not set to an instance of an object.
Thanks, friends. Check the codes. See what I should do to avoid this error, and is this process correct, you think?. Thankful