Ari*_*Sam 5 c# sql-server asp.net-mvc ado.net rdlc
我正在做mvc报道,我对此非常陌生.我正在尝试创建一个报告,我已经使用rdlc完成了.一切运作良好,可以导出为各种格式.使用rdlc时我的问题是我们需要先设计并绑定它.如何创建一个空的rdlc模板,设计并以编程方式将其与数据集绑定.
到目前为止我的工作(使用空的rdlc模板 - 刚创建没有任何表的文件),
控制器文件,
public ActionResult Report(string id)
{
DB.Open();
LocalReport lr1 = new LocalReport();
string path1 = Path.Combine(Server.MapPath("~/Report"), "TestEmptyReport.rdlc");
lr1.ReportPath = path1;
DataTable pc2a = new DataTable();
pc2a = DB.getDataSet().Tables[0];
pc2a.Columns.Add("Product Name");
pc2a.Columns.Add("Price");
pc2a.Columns.Add("Quantity");
ReportDataSource rdc = new ReportDataSource("DataSet1", pc2a);
lr1.DataSources.Add(rdc);
string reportType = id;
string mimeType;
string encoding;
string fileNameExtension;
string deviceInfo =
"<DeviceInfo>" +
"<OutputFormat>" + id + "</OutputFormat>" +
"<PageWidth>8.5in</PageWidth>" +
"<PageHeight>11in</PageHeight>" +
"<MarginTop>0.5in</MarginTop>" +
"<MarginLeft>1in</MarginLeft>" +
"<MarginRight>1in</MarginRight>" +
"<MarginBottom>0.5in</MarginBottom>" +
"</DeviceInfo>";
Warning[] warnings;
string[] streams;
byte[] renderedBytes;
renderedBytes = lr1.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
return File(renderedBytes, mimeType);
}
Run Code Online (Sandbox Code Playgroud)
模型文件,
public DataSet getDataSet()
{
string query = "SELECT * FROM tblproduct";
if (con.State.ToString() == "Open")
{
SqlDataAdapter ad = new SqlDataAdapter(query, con);
DataSet ds = new DataSet("tblproduct");
ad.Fill(ds);
return ds;
}
else
{
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
查看文件,
<div style="padding: 10px; border: 1px solid black">
<div><a href="@Url.Action("Report", new { id = "PDF" })">Get PDF Report</a></div>
<div><a href="@Url.Action("Report", new { id = "Excel" })">Get Excel Report</a></div>
<div><a href="@Url.Action("Report", new { id = "Word" })">Get Word Report</a></div>
<div><a href="@Url.Action("Report", new { id = "Image" })">Get Image Report</a></div>
Run Code Online (Sandbox Code Playgroud)
数据在那里,但我不知道如何将其与rdlc连接.意味着根据数据创建列,并用从sql server调用的数据填充它.
TQVM在高级.解释和示例或任何其他方法将有所帮助.
如果我正确理解您的问题,您想从空白 RDLC 创建报告。您必须在设计时告知 RDLC 文件有关数据的信息。您可以在设计时通过添加列或来自另一个表的列或进行联接来自定义报告。
而通过 C# 的动态 RDLC 生成器可以从 RDLC 动态生成报告。由于完整的 ReportingEngine 是定制的,但非常通用。复制粘贴可能有助于生成报告。
| 归档时间: |
|
| 查看次数: |
7549 次 |
| 最近记录: |