您好,
需要使用动态数据源绑定。思路是动态构成SQL查询赋值成一个DataSet,报表绑定这个DataSet。
如果是web应用,需要绑定WebViewer1_LocateDataSource方法。其它环境下有类似的方法。
- protected void WebViewer1_LocateDataSource(object sender, GrapeCity.ActiveReports.LocateDataSourceEventArgs args)
- {
- string productId = args.Report.Parameters[0].Label;
- //string productId = "1000";
- string connStr = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};", Server.MapPath("/Data/Reels.mdb"));
- string productSql = string.Format("SELECT * From Product where productId = {0}",productId);
- DataLayer dl = new DataLayer(connStr, productSql);
- args.Data = dl.DataSetData.Tables["Products"];
- }
复制代码- internal sealed class DataLayer
- {
- private DataSet dataSetData;
- public DataLayer(string connStr, string productSql)
- {
- LoadDataToDataSet(connStr, productSql);
- }
- public DataSet DataSetData
- {
- get { return dataSetData; }
- }
- private void LoadDataToDataSet(string connStr,string productSql)
- {
- dataSetData = new DataSet();
- OleDbConnection conn = new OleDbConnection(connStr);
- OleDbCommand cmd = new OleDbCommand(productSql, conn);
- OleDbDataAdapter adapter = new OleDbDataAdapter();
- adapter.SelectCommand = cmd;
- adapter.Fill(dataSetData, "Products");
- }
- }
复制代码
可以参考以下博客
http://blog.gcpowertools.com.cn/ ... Source_RunTime.aspx |