I'm trying to assign datasource to a subreport in the masterreport after InitializeComponent() and the data doesn't seem to be loading. I've tried with SqlDataAdapter, DataSet, I've also tried assigning in the needdatasouce event and nothing seems to work. Please let me know how I can do it. I also need to pass parameters from the master to the subreport at the time of loading (not from any datafields or textboxes but predetermined).
public masterform()
{
InitializeComponent();
//instantiate subreport form here.
//I get SqlAdapter da here
this.detailSubReport.ReportSource = subreportform;
this.detailSubReport.ReportSource.DataSource = da;
}
Thanks,
Laxmi
3 Answers, 1 is accepted
We have tried to reproduce your problem without any success. Specifying an SqlDataAdapter for the SubReport.ReportSource.DataSource property seems to work perfectly for us. Probably there is some problem with the way you retrieve your data, but without more information we can only speculate on that matter. The attached ZIP archive contains an example test report with a sub-report that uses an SqlDataAdapter as a DataSource. You will need the AdventureWorks database, that comes with our installation, to run the example. For a more sophisticated example on SubReport data binding you can see our ProductLineSales sample report.
All the best,
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

Thanks for the reply. I tried with your code again (had tried that way earlier0 and it doesn't seem to populate the data at the runtime. The only thing that works is assigning to another report that has a datasource created at design time. The way I have created my subreport was I dragged and dropped a subreport control onto the master report and did not assign any datasource in the design (so it does not have any dataset or dataadapter created in design). I try to assign the datasource in the master report after InitializeComponent() line per my second piece of code below.
(1)
this.SubReport1.ReportSource = new Report1();
(the code works fine with the above line as it has datasource assigned at the designtime)
(2)
const
string connectionString = "Data Source=;Initial Catalog=;User Id=;Password=;Persist Security Info=true;";
const string detailQuery = "select * from table1";
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand detailCommand = new SqlCommand(detailQuery, connection);
SqlDataAdapter detailAdapter = new SqlDataAdapter(detailCommand);
this.SubReport1.ReportSource = new Report2();
this.SubReport1.ReportSource.DataSource = detailAdapter;
(Report2 does not have any datasource assigned at designed time and hence has no dataset/dataadapter created and the code above does not populate the subreport Report2 either at the runtime).
Please let me know if you need any more information. I'll greatly appreciate if you can let me know what I need to do or what I might be missing at the earliest.
Btw, I'm using Telerik Reporting Q2 2008.
Thanks,
Laxmi
I have tested the code, that I have already sent you against the Q2 2008 version and it seems to work just fine. I am really surprised it does not work for you. Perhaps, something else is going on here... Could you, please, try to replace the code in the MasterReport constructor after the InitializeComponent() method with the following one:
const string connectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=True"; |
const string masterQuery = "select ProductSubcategoryID, Name from Production.ProductSubcategory"; |
const string detailQuery = "select ProductID, ProductSubcategoryID, Name from Production.Product"; |
SqlConnection connection = new SqlConnection(connectionString); |
SqlCommand masterCommand = new SqlCommand(masterQuery, connection); |
SqlCommand detailCommand = new SqlCommand(detailQuery, connection); |
SqlDataAdapter masterAdapter = new SqlDataAdapter(masterCommand); |
SqlDataAdapter detailAdapter = new SqlDataAdapter(detailCommand); |
DataSet masterDataSet = new DataSet(); |
DataSet detailDataSet = new DataSet(); |
masterAdapter.Fill(masterDataSet); |
detailAdapter.Fill(detailDataSet); |
this.DataSource = masterDataSet; |
this.subReport.ReportSource = new DetailReport(); |
this.subReport.ReportSource.DataSource = detailDataSet; |
What happens when you run the report this time? Does it throw an exception? If not, do you have any data at all in the masterDataSet and detailDataSet, after the masterAdapter.Fill() and detailAdapter.Fill() methods are invoked?
If the above test does not help you locate the problem, could you, please, send us your report, so we can better reproduce the issue you are experiencing ourselves.
Kind regards,
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.