我不想从代码中创建DataSet并将其设置为水晶报表的数据源.
如果不需要,我不想在 VS 中创建 DataSet xsd 文件.只是纯代码.
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.填充u数据集会自动填充报表列.
There is only way out. As suggested by rosado. Little bit explained 1. 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.
下面是我的一个项目的示例代码.
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();
这篇关于如何将水晶报表绑定到手动创建的数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!