Transfer data from Dataset to Report Viewer
-
Gentleman, And so it goes... I created the following code to accept data from my dataset on another page and propagate it in a report viewer.
private void DisplayReport_Load(object sender, EventArgs e)
{
dataGridViewReport.DataSource = null;
DataTable dt = ds.Tables[0];
dataGridViewReport.DataSource = ds.Tables[0].DefaultView;this.reportViewer1.Reset(); this.reportViewer1.LocalReport.ReportPath = Application.StartupPath + @" \\Report1.rdlc"; ReportDataSource rds = new ReportDataSource("Precheck Report", dt); reportViewer1.LocalReport.DataSources.Clear(); reportViewer1.LocalReport.DataSources.Add(rds); reportViewer1.RefreshReport(); }
When the page loads, this page accepts the dataset value from the constructor and uses it in the code above. This has been an ordeal up until now, but I think this might be close. I think the problem might be that the report file cannot be found. Now, when I created the report file (Report1.rdlc), it appears with the other form files. What I thought I read is that this would then be located, on RUNTIME, in the /bin OR /release folder, but it does not appear to be there, nor can I copy it to that location. I cannot find where the actual path is, only the path while it is not running. So ... first, I am not sure if I have the code correct to create the report but it is no longer throwing any errors. The view display simply says that it cannot locate this file. And second, just where should I be pointing at so that this code (or any code) has the correct path to the file so the report can be created. Thank You!
-
Gentleman, And so it goes... I created the following code to accept data from my dataset on another page and propagate it in a report viewer.
private void DisplayReport_Load(object sender, EventArgs e)
{
dataGridViewReport.DataSource = null;
DataTable dt = ds.Tables[0];
dataGridViewReport.DataSource = ds.Tables[0].DefaultView;this.reportViewer1.Reset(); this.reportViewer1.LocalReport.ReportPath = Application.StartupPath + @" \\Report1.rdlc"; ReportDataSource rds = new ReportDataSource("Precheck Report", dt); reportViewer1.LocalReport.DataSources.Clear(); reportViewer1.LocalReport.DataSources.Add(rds); reportViewer1.RefreshReport(); }
When the page loads, this page accepts the dataset value from the constructor and uses it in the code above. This has been an ordeal up until now, but I think this might be close. I think the problem might be that the report file cannot be found. Now, when I created the report file (Report1.rdlc), it appears with the other form files. What I thought I read is that this would then be located, on RUNTIME, in the /bin OR /release folder, but it does not appear to be there, nor can I copy it to that location. I cannot find where the actual path is, only the path while it is not running. So ... first, I am not sure if I have the code correct to create the report but it is no longer throwing any errors. The view display simply says that it cannot locate this file. And second, just where should I be pointing at so that this code (or any code) has the correct path to the file so the report can be created. Thank You!
You need to check the "Properties" (Build Action; Copy ... option) of the report in Solution Explorer ... That will tell you where the report winds up. Consider making the report an "embedded resource" and referencing it that way. (Review your LocalReport object options).
-
You need to check the "Properties" (Build Action; Copy ... option) of the report in Solution Explorer ... That will tell you where the report winds up. Consider making the report an "embedded resource" and referencing it that way. (Review your LocalReport object options).
-
Thank you Gerry. I did both. No Difference. I appreciate your response. Any followup and I'll be looking. I'm a few days into this problem and I have gone nowhere. Rare for me and a total waste of my time. Appreciate your advice. Pat
-
Maybe check your path name again (your post has a "blank\" in the report's file name). The "embedded resource name" depends on the namespace; it's not the same as a report's "file name / path".
Thanks Gerry. I removed the space. No difference. I put a in complete long hand path id. No Difference. No Errors. Datagrid is fully populated. I tried alternating between dataset and dataTable. Nothing. No errors. Just sits there blank. I almost feel angry that there is no easy way to take the data that is just sitting there in the grid and moving it into the report. This is do-able with Excel. But I have chosen not to do that in this case. I did not want to use Crystal Reports (never liked them), and now I am not sure if that will work either, but I certainly need a solution. I regularly use Code Project (since Y2K days), but this may be the first time in over 10 years that I cannot neither get nor figure out a solution. I greatly appreciate your time and expertise. I'll keep looking. Thank You. Pat