Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Transfer data from Dataset to Report Viewer

Transfer data from Dataset to Report Viewer

Scheduled Pinned Locked Moved C#
helpannouncement
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PDTUM
    wrote on last edited by
    #1

    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!

    L 1 Reply Last reply
    0
    • P PDTUM

      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!

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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).

      P 1 Reply Last reply
      0
      • L Lost User

        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).

        P Offline
        P Offline
        PDTUM
        wrote on last edited by
        #3

        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

        L 1 Reply Last reply
        0
        • P PDTUM

          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

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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".

          P 1 Reply Last reply
          0
          • L Lost User

            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".

            P Offline
            P Offline
            PDTUM
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups