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. Connecting a Report (.rdlc) and (.mdf) file programmetically

Connecting a Report (.rdlc) and (.mdf) file programmetically

Scheduled Pinned Locked Moved C#
database
3 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.
  • C Offline
    C Offline
    csetopper_bhanu
    wrote on last edited by
    #1

    Hello all, I want to add values from my database (.mdf) file to my report file (.rdlc) file. As far as I knw, it can be done by making a dataset and then by drag-n-drop we can add values to report at run time. All I want to do is to add values to (.rdlc) file at run time through absolute code, no drag-n-drop. Plz suggest me the ways do do it... Thanks in advance !!!

    csetopper_bhanu

    M 1 Reply Last reply
    0
    • C csetopper_bhanu

      Hello all, I want to add values from my database (.mdf) file to my report file (.rdlc) file. As far as I knw, it can be done by making a dataset and then by drag-n-drop we can add values to report at run time. All I want to do is to add values to (.rdlc) file at run time through absolute code, no drag-n-drop. Plz suggest me the ways do do it... Thanks in advance !!!

      csetopper_bhanu

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      The following code is from our reportviewer initialisation. You must have created the report of course. Datatable(s) are loaded by the form that allows the user to select the report and fill in the paramters.

      public partial class frmReportViewer : Form
      

      {
      public frmReportViewer(string sReportFile, DataTable dtReportData)
      {
      InitializeComponent();
      ReportFile = sReportFile;
      ReportData = dtReportData;
      }
      private string ReportFile { get; set; }
      private string NameSpace { get; set; }
      private DataTable ReportData { get; set; }

      private void frmReportViewer\_Load(object sender, EventArgs e)
      {
      	try
      	{
      		string sPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\\\Reports";
      		ReportData.TableName = "dtReport";
      		DataSet oDS = ReportData.DataSet;
      		oDS.DataSetName = "ReportData";
      		string RepResource = "FinBranch.Reports." + ReportFile + ".rdlc";
      		//string sFile = Path.Combine(sPath, ReportFile);
      		
      		repViewer.Reset();
      		//repViewer.LocalReport.ReportPath = sFile;
      		//note the report has to be in the resource
      		repViewer.LocalReport.ReportEmbeddedResource = RepResource;
      		repViewer.LocalReport.DataSources.Add(new ReportDataSource("ReportData", oDS.Tables\[0\]));
      		
      		this.repViewer.RefreshReport();
      	}
      	catch (Exception)
      	{ 
      		throw; 
      	}
      	}
      

      Never underestimate the power of human stupidity RAH

      C 1 Reply Last reply
      0
      • M Mycroft Holmes

        The following code is from our reportviewer initialisation. You must have created the report of course. Datatable(s) are loaded by the form that allows the user to select the report and fill in the paramters.

        public partial class frmReportViewer : Form
        

        {
        public frmReportViewer(string sReportFile, DataTable dtReportData)
        {
        InitializeComponent();
        ReportFile = sReportFile;
        ReportData = dtReportData;
        }
        private string ReportFile { get; set; }
        private string NameSpace { get; set; }
        private DataTable ReportData { get; set; }

        private void frmReportViewer\_Load(object sender, EventArgs e)
        {
        	try
        	{
        		string sPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\\\Reports";
        		ReportData.TableName = "dtReport";
        		DataSet oDS = ReportData.DataSet;
        		oDS.DataSetName = "ReportData";
        		string RepResource = "FinBranch.Reports." + ReportFile + ".rdlc";
        		//string sFile = Path.Combine(sPath, ReportFile);
        		
        		repViewer.Reset();
        		//repViewer.LocalReport.ReportPath = sFile;
        		//note the report has to be in the resource
        		repViewer.LocalReport.ReportEmbeddedResource = RepResource;
        		repViewer.LocalReport.DataSources.Add(new ReportDataSource("ReportData", oDS.Tables\[0\]));
        		
        		this.repViewer.RefreshReport();
        	}
        	catch (Exception)
        	{ 
        		throw; 
        	}
        	}
        

        Never underestimate the power of human stupidity RAH

        C Offline
        C Offline
        csetopper_bhanu
        wrote on last edited by
        #3

        thnx

        csetopper_bhanu

        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