print problem with rdlc
I am going to create print page in wpf with *.rdlc. For this , i create a class(following is this codes). I bind the class to report but when i run the program , following message occurs :
A data source instant has not been supplied for data source 'dataset1'
class rpt_insurance
{
private string _insurance;
private int _count_print;
private int _sum_tariff;
private int _lot_org;
public string insurance
{
get { return _insurance; }
set { _insurance = value; }
}
public int count_print
{
get { return _count_print; }
set { _count_print = value; }
}
public int sum_tariff
{
get { return _sum_tariff; }
set { _sum_tariff = value; }
}
public int lot_org
{
get { return _lot_org; }
set { _lot_org = value; }
}
public DataTable report_insurance(string from_date,string to_date)
{
using (doctorEntities de = new doctorEntities())
{
var print = (from Table_infobase_print tip in de.Table_infobase_print
where tip.Print_date.CompareTo(from_date) > 0 && tip.Print_date.CompareTo(to_date) < 0
select tip).ToList();
var insurance = (from Table_insurance_org tio in de.Table_insurance_org
select tio).ToList();
List<rpt_insurance> lri = new List<rpt_insurance>();
foreach (var insurance_row in insurance)
{
rpt_insurance ri = new rpt_insurance();
int number = 0;
foreach (var print_row in print)
{
if(print_row.insurance_org==insurance_row.org_name)
{
number++;
ri.insurance = print_row.insurance_org;
ri.count_print = number;
ri.sum_tariff = ri.sum_tariff + print_row.sum_tariff;
ri.lot_org=lot_org+(print_row.sum_tariff-print_row.sum_lot_patient);
}
}
if (ri.insurance != null)
{
lri.Add(ri);
}
}
DataTable dt = new DataTable();
dt = new DataTable();
dt.Columns.A开发者_如何转开发dd("cinsurance");
dt.Columns.Add("ccount_print");
dt.Columns.Add("csum_tariff");
dt.Columns.Add("clot_org");
for (int i = 0; i < lri.Count; i++)
{
DataRow dr = dt.NewRow();
dr["cinsurance"] = lri[i].insurance;
dr["ccount_print"] = lri[i].count_print;
dr["csum_tariff"] = lri[i].sum_tariff;
dr["clot_org"] = lri[i].lot_org;
dt.Rows.Add(dr);
}
return dt;
}
}
}
You need to supply the dataset to your report. Something like:
viewer.LocalReport.DataSources.Add(new ReportDataSource("dataset1", dataTable));
Edit: based on your comment
private void Window_Loaded(object sender, RoutedEventArgs e)
{
var dataTable = report_insurance(fromDate, toDate);
viewer_insurance.LocalReport.ReportPath = "E:\\desktop\\Doctor\\Project\\Doctor\\Doctor\\rinsurance.rdlc";
viewer_insurance.LocalReport.DataSources.Add(new ReportDataSource("dataset1", dataTable);
viewer_insurance.RefreshReport();
}
You really can't get around the need to call your data retrieval method AND send that data through to the report.
精彩评论