问题描述
我wan't从code创建数据集,并将其设置为水晶报表数据源。
我不想创建VS一个DataSet XSD文件,如果我没有。只是纯粹的code。
I wan't to create DataSet from code and set it as data source for crystal report.
I don't want to create a DataSet xsd file in VS if I don't have to. Just pure code.
DataSet ds = new DataSet();
DataTable tbl = new DataTable();
DataColumn cln = new DataColumn();
// I fill row, columns, table and add it to ds object
...
后来,当我需要的报告中,我使用:
Then when I need report I use:
myReport.SetDataSource(ds);
这里的问题是我不知道如何绑定这个报告?如何添加字段?
我有一个文本和二进制数据(图像)。
The problem here is I don't know how to bind this to report? How to add fields?
I have a text and binary data (image).
推荐答案
有是唯一的出路。至于建议的罗萨多。点点解释
1.创建一个RPT文件。
2.创建具有所需列的XSD。
3.将滴在RPT列。格式化的要求。
4.现在创建连接,使用适配器来填充该数据集。
5,灌装ü数据会自动填充报表列。
There is only way out. As suggested by rosado. Little bit explained1. CReate a RPT File. 2. Create a XSD with the desired columns.3. Drag drop the columns on the rpt. Format it as required.4. Now create connection, use adapter to fill that dataset.5. Filling u dataset will automatically fill the report columns.
下面是我的项目的一个样本code。
Below is a sample code from one of mine project.
Invoice invoice = new Invoice(); // instance of my rpt file
var ds = new DsBilling(); // DsBilling is mine XSD
var table2 = ds.Vendor;
var adapter2 = new VendorTableAdapter();
adapter2.Fill(table2);
var table = ds.Bill;
var adapter = new BillTableAdapter();
string name = cboCustReport.Text;
int month = int.Parse(cboRptFromMonth.SelectedItem.ToString());
int year = int.Parse(cboReportFromYear.SelectedItem.ToString());
adapter.Fill(table, name,month,year);
ds.AcceptChanges();
invoice.SetDataSource(ds);
crystalReportViewer1.ReportSource = invoice;
crystalReportViewer1.RefreshReport();
这篇关于如何绑定水晶报表到手动创建的DataSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!