Nếu bạn cần từ đầu, xem xét bạn cần dữ liệu DataGridView in hiển thị trong Crystelreport sử dụng XML
**(This is very helpful if you not using any database)**
- làm đầu tiên bảng dữ liệu
- Rồi Thêm dữ liệu vào bảng dữ liệu (đây thêm từ DataGridview)
- Tạo tệp XML
- Chạy báo cáo
Đây Mẫu Mã
DataTable dt = new DataTable();
dt.Columns.Add("Item_Id", typeof(string));
dt.Columns.Add("Categry", typeof(string));
dt.Columns.Add("Item_Name", typeof(string));
dt.Columns.Add("Unit_Price", typeof(double));
dt.Columns.Add("Quantity", typeof(int));
dt.Columns.Add("Discount", typeof(string));
dt.Columns.Add("Total_Payable", typeof(double));
foreach (DataGridViewRow dgr in DGVsell.Rows)
{
dt.Rows.Add(dgr.Cells[0].Value, dgr.Cells[1].Value, dgr.Cells[2].Value, dgr.Cells[3].Value, dgr.Cells[4].Value, dgr.Cells[5].Value, dgr.Cells[6].Value);
}
ds.Tables.Add(dt);
ds.WriteXmlSchema("Bill.xml");
lưu ý Nếu lỗi đã làm thay đổi Xml App.config tập tin như sau
<?xml version="1.0" encoding="utf-8"?>
<configuration>
</startup>-->
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
Sau khi tệp xml đánh dấu, bạn có thể gọi đến Báo cáo Crystel
frmreport obj = new frmreport(); //load report viwer form
obj.ShowDialog();
trong báo cáo viwer
crBill cr = new crBill();
cr.SetDataSource(frmSell.ds);
crystalReportViewer1.ReportSource = cr;
crystalReportViewer1.RefreshReport();
crystalReportViewer1.Refresh();
Nguồn
2017-04-05 10:39:42
Bạn có thể vui lòng đăng mã để tải báo cáo từ xml không? – Urik
@Urik: Không có mã. Báo cáo được liên kết với tệp XML. –
Nhưng không phải bạn đang sử dụng một cái gì đó như rpt.Database.Tables [0] .SetDataSource (ds_xml); ? – Urik