您好,您的问题解答如下:
报表资源管理器中的数据源,是为了快速在开发环境下设计出报表来,实际项目部署后,数据源可灵活切换(表结构、字段相同)
这里有源码供您参考:
- private void btnDataSet_Click(object sender, System.EventArgs e)
- {
- this.Cursor = Cursors.WaitCursor;
- //Dataset to hold data.
- DataSet _InvoiceData = new DataSet();
- _InvoiceData.Locale = CultureInfo.InvariantCulture;
- //Database connection populated from the sample Northwind access database
- OleDbConnection _nwindConn = new OleDbConnection();
- _nwindConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\rogerwang\\Documents\\ComponentOne Samples\\ActiveReports 8\\Data\\NWIND.MDB;Persist Security Info=False";
- //Run the SQL command.
- OleDbCommand _selectCMD = new OleDbCommand("SELECT * FROM Invoices ORDER BY Customers.CompanyName, OrderID", _nwindConn);
- _selectCMD.CommandTimeout = 30;
- //Data adapter used to run the select command
- OleDbDataAdapter _InvoicesDA = new OleDbDataAdapter();
- _InvoicesDA.SelectCommand = _selectCMD;
- //Fill the DataSet.
- _InvoicesDA.Fill(_InvoiceData, "Invoices");
- //Create the report and assign the data source.
- Invoice rpt = new Invoice();
- rpt.DataSource = _InvoiceData;
- rpt.DataMember = _InvoiceData.Tables[0].TableName;
- arvMain.Document = new ActiveReports.Document.SectionDocument();
- //Run and view the report.
- rpt.Run(false);
- arvMain.Document = rpt.Document;
- this.Cursor = Cursors.Arrow;
- }
复制代码
更多源码,请参考安装AR8后自带的5个数据源的示例:
C:\Users\rogerwang\Documents\ComponentOne Samples\ActiveReports 8\Section Reports\C#\Data |