Reputation: 1021
I have used Data set to bind my rdlc reports using my Stored Procedure. Can I bind a manipulated data table to my rdlc report instead of Data set(.xsd).
Upvotes: 0
Views: 39352
Reputation: 45490
Your reportViewer on ASPX
<rsweb:ReportViewer ID="ReportViewer1" runat="server" SizeToReportContent="True">
</rsweb:ReportViewer>
Method to get data set
private DataTable GetSPResult()
{
DataTable ResultsTable = new DataTable();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString);
try
{
SqlCommand cmd = new SqlCommand("yourStorePorcedure", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@id", 1);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(ResultsTable);
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
finally
{
if (conn != null)
{
conn.Close();
}
}
return ResultsTable;
}
Bind result to reportviewer
DataTable dt = GetSPResult();
ReportViewer1.Visible = true;
ReportViewer1.LocalReport.ReportPath = "Report1.rdlc";
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dt));
Add DataSet to your Project, then add a tableadapter to it:
Go through the wizard and create the entity using the store procedure
Then Make sure the DataSet file is added to your rdlc
Now you need to design , and add the fields or it will be blank
Upvotes: 6
Reputation: 517
Yes we can use manipulated datatable as datasource to report.but the field name should be same.
DataTable dtReportData="yourdata source"
YourReportViewer.LocalReport.DataSources.Clear();
ReportDataSource RDS1 = new ReportDataSource("SampleReport", dtReportData);
YourReportViewer.ProcessingMode = ProcessingMode.Local;
YourReportViewer.LocalReport.EnableExternalImages = true;
YourReportViewer.LocalReport.ReportEmbeddedResource = "Your Report Path";
YourReportViewer.LocalReport.DataSources.Add(RDS1);
Upvotes: 4