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