How to run a rdlc using coding
I have created an rdlc
where I have used dataset taken as a new item in solution explorer for designing my report. After binding my report from that datasource
which is named as Dataset1
. I have created its object and tried to fill this datasource
using coding. Now when I runs the following code I am not getting any result.
What can be the issue?
reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
LocalReport localReport = reportViewer1.LocalReport;
localReport.DataSources.Clear();
localReport.ReportPath = @"E:\Projects\Manojp\AARFID_SSRS_Report\WindowsFormsApplication1\WindowsFormsApplication1\Local Report\rptTest.rdlc";
// DataSet dataset = new DataSet("AARFID_Report");
DataSet1 ds = new DataSet1();
// fill the Data Set from DataBase.
//ds.Tables.Remove("M_GUEST");
ds.Tables.Clear();
GetData(ref ds);
//
// Create a report data source for the sales order data
ReportDataSource rds = new ReportDataSource();
rds.Name = "AA";
rds.Value = ds.Tables[0];
localReport.DataSources.Add(rds);
// reportViewer1.LocalReport.DataSources.Add(rds);
reportViewer1.RefreshReport();
localR开发者_运维技巧eport.DataSources.Clear();
GetData()
do this:
connection.Open();
ad.Fill(ds,"M_GUEST");
connection.Close();
In the report view a message is shown as:
A data source instance has not been supplied for the data source 'dtaset1_m_guest'
Make sure the names of datasets in the rdl file and the report generator match!
The easiest way would be to have a DataSet, DataSource and the instances named "M_GUEST". Also, do not clear the data sources before rendering.
This line
rds.Name = "AA";
must match the name of the data set defined in the report. In your case, that would be
rds.Name = "dtaset1_m_guest";
When you add .rdlc report in your project by wizard then by default it take dataset name as 'DataSet1' . Now if you want to bind dynamically new dataset then name of that dataset must be 'DataSet1'. Try change it and also check that Table[0] contains some data(Rows) for which DataType get matched with original dataType of 'DataSet1'. If DataType doesn't matches then data wont come in your ReportViewer. Try this code:-
string exeFolder = (Path.GetDirectoryName(Application.StartupPath)).Substring(0, (Path.GetDirectoryName(Application.StartupPath)).Length - 3);
string reportPath = Path.Combine(exeFolder, @"Reports\SessionReport.rdlc");
Microsoft.Reporting.WinForms.ReportDataSource rds = new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", ds.Tables[0]);
this.reportViewer1.LocalReport.DataSources.Add(rds);
this.reportViewer1.LocalReport.ReportPath = reportPath;
this.reportViewer1.RefreshReport();
For more detail about .rdlc report(Core logic) refer following link How to create report (RDLC) without database?
If the DataSource in binding is named "Dataset1" then the one you your in code should also name the same.
I add it like this works perfectly do this as below:
reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("Dataset1", ds.Tables[0]));
精彩评论